Score:0

Install gcc/g++ 6 on Ubuntu 21.04

cn flag

I am trying to compile Cuda 10.2 and predictably gcc-10 will not work to compile it. When using 20.04 it was simple, add bionic repo, update, install, update-alternatives. Using 21.04 I cannot get anything to work.

I tried with both xenial and bionic 'main' and 'universe' repos, which throws an error about the PUBKEY. I got the PUBKEYs from the ubuntu keyserver and update the package list, no errors.

sudo apt install g++-6

Package g++-6 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'g++-6' has no installation candidate

sources.list ->

deb http://archive.ubuntu.com/ubuntu hirsute restricted main multiverse universe

deb http://archive.ubuntu.com/ubuntu hirsute-updates restricted main multiverse universe

deb http://archive.ubuntu.com/ubuntu hirsute-security restricted main multiverse universe

# gcc-6
deb [allow-insecure=yes] http://dk.archive.ubuntu.com/ubuntu/ bionic main universe
#deb [allow-insecure=yes] http://dk.archive.ubuntu.com/ubuntu/ xenial main universe

Does anyone know how I can achieve this using Ubuntu 21.04? Every post I have read says to add the bionic or xenial repos, update, install. I have had no luck so far.

cocomac avatar
cn flag
Just a heads-up... I went to [the CUDA website](https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu), and it does not list 21.04 as a version you can download. I suggest instead [downloading CUDA 11.4](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04), which at least supports 20.04. You could see if it works in 21.04. I don't know.
cocomac avatar
cn flag
Also, I think you have [an XY Problem](https://meta.stackexchange.com/a/66378/1081494). If you tell us _why_ you want CUDA 10.2, and why you want to compile it yourself, we can try to help.
baudneo avatar
cn flag
I am installing CUDA 10.2 in an lxc to run some object detection software. I ended up grabbing most of the packages and installing manually.
Score:0
cn flag

I grabbed the packages (.deb) I needed from browsing the Ubuntu repos here.

Here is a list of the .deb packages I needed to manually install gcc/g++ 6. Install in the order of the list. This assumes you have most of the tools needed to compile and are just looking to switch default gcc versions.

sudo apt install ./libisl19_0.19-1_amd64.deb
sudo apt install ./gcc-6-base_6.4.0-17ubuntu1_amd64.deb
sudo apt install ./cpp-6_6.4.0-17ubuntu1_amd64.deb

# you can grab this next package from 21.04 repos, it handles a lot of the dependancies.
sudo apt install libgcc-6-dev

# Finally
sudo apt install ./gcc-6_6.4.0-17ubuntu1_amd64.deb

# GCC-6 is now installed, you can test by gcc-6 -v
baudneo@ZMES-test:~$ gcc-6 -v
gcc version 6.4.0 20180424 (Ubuntu 6.4.0-17ubuntu1)

# Now for G++ 6
sudo apt install ./libstdc++-6-dev_6.4.0-17ubuntu1_amd64.deb
sudo apt install ./g++-6_6.4.0-17ubuntu1_amd64.deb

# G++-6 is now installed! test by g++-6 -v
baudneo@ZMES-test:~$ g++-6 -v
gcc version 6.4.0 20180424 (Ubuntu 6.4.0-17ubuntu1)

# Now it is time to configure the system to use GCC G++ 6
# This assumes you do not have other versions of gcc and g++ installed for other projects

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 100
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 100
sudo update-alternatives --set c++ /usr/bin/g++
# When you want to revert these back to default gcc-10
sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
sudo update-alternatives --set c++ /usr/bin/g++
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.