It's possible you arrived because something blew up with nvidia. (I'm on cudatoolkit 11.4 and actually downgrading got me out of trouble - your mileage may vary.)
sudo apt install gcc-9 g++-9
sudo mkdir /usr/local/cuda/bin
sudo ln -s /usr/bin/gcc-9 /usr/local/cuda/bin/gcc
WARNING - I recommend using timeshift to make a backup of your working system. https://github.com/teejee2008/timeshift
This will get you the latest gcc 11
sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo apt-get install g++-11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 100
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 50
sudo update-alternatives --set g++ /usr/bin/g++-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo update-alternatives --set cpp-bin /usr/bin/cpp-11
gcc --version
gcc (Ubuntu 11-20210417-1ubuntu1) 11.0.1 20210417
Copyright (C) 2021 Free Software Foundation, Inc.
Answer from johndpope on Stack OverflowIt's possible you arrived because something blew up with nvidia. (I'm on cudatoolkit 11.4 and actually downgrading got me out of trouble - your mileage may vary.)
sudo apt install gcc-9 g++-9
sudo mkdir /usr/local/cuda/bin
sudo ln -s /usr/bin/gcc-9 /usr/local/cuda/bin/gcc
WARNING - I recommend using timeshift to make a backup of your working system. https://github.com/teejee2008/timeshift
This will get you the latest gcc 11
sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo apt-get install g++-11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 100
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 50
sudo update-alternatives --set g++ /usr/bin/g++-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo update-alternatives --set cpp-bin /usr/bin/cpp-11
gcc --version
gcc (Ubuntu 11-20210417-1ubuntu1) 11.0.1 20210417
Copyright (C) 2021 Free Software Foundation, Inc.
From the looks of it, inside your conda environment, the gcc command has been linked to /home/ubuntu/anaconda3/envs/tensorflow_p36/bin/gcc, and the version is 4. Whereas outside the environment, the only gcc on the path is gcc-8, which corresponds to version 8.
Also, as you've observed, you are unable to create an alternative for gcc because it is linked to g++ alternative.
I also prefer to have gcc be the main alternative, and all other tools (including g++) follow suit. In this case, I will start by deleting the g++ alternative:
sudo update-alternatives --remove-all g++
Now that we've got that out of the way, we can create one for gcc which links to gcc-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-8 --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-8 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-8
References
- https://askubuntu.com/a/26518/145907
- https://askubuntu.com/a/1206264/145907
raspbian - Problem with gcc/g++ versions - Raspberry Pi Stack Exchange
Problems after a recent update
Did you change your compiler version? Make sure you have the default popos version of gcc, same as was used to compile the kernel.
Run the driver install script from an unmodified environment, without thatever custom dev stuff you have added.
For me it says:
cc --versioncc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Or maybe I DID upgrade mine and forgot :) Try: sudo apt install gcc-12
More on reddit.com[ERROR] | update-alternatives: error: alternative g++ can't be slave of gcc: it is a master alternative
unconfigured packages after ubuntu upgrade
First erase the current update-alternatives setup for gcc and g++:
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
Install Packages
It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:
sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4
Install Alternatives
Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (Note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
Configure Alternatives
The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Or switch using script:
#!/bin/sh
if [ -z "$1" ]; then
echo "usage: $0 version" 1>&2
exit 1
fi
if [ ! -f "/usr/bin/gcc-
1" ]; then
echo "no such version gcc/g++ installed" 1>&2
exit 1
fi
update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
execute in terminal :
gcc -v
g++ -v
Okay, so that part is fairly simple. The tricky part is that when you issue the command GCC it is actually a sybolic link to which ever version of GCC you are using. What this means is we can create a symbolic link from GCC to whichever version of GCC we want.
- You can see the symbolic link :
ls -la /usr/bin | grep gcc-4.4 ls -la /usr/bin | grep g++-4.4
- So what we need to do is remove the GCC symlink and the G++ symlink and then recreate them linked to GCC 4.3 and G++ 4.3:
rm /usr/bin/gcc rm /usr/bin/g++ ln -s /usr/bin/gcc-4.3 /usr/bin/gcc ln -s /usr/bin/g++-4.3 /usr/bin/g++
- Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.3 and G++ 4.3:
ls -la /usr/bin/ | grep gcc ls -la /usr/bin/ | grep g++
- Finally we can check our GCC -v again and make sure we are using the correct version:
gcc -v g++ -v
I recently moved to my new place and wasn't on my laptop for about a week. I went to start up my laptop and run updates before gaming with my daughter. I noticed that there was an update for Nvidia-driver-535 available. I thought I already had it but it had the install button next to it. So I ran the normal OS updates, updates for some apps, and for the Nvidia driver.
After the update I ran my commands to:
watch -n 2 sensors
watch watch -n 2 nvidia-smi
Watch sensors worked normally but now I am getting an error for nvidia-smi. I tried to run Nvidia System Monitor Qt but that came back with a critical error as well. Both messages are in the screenshot below.
I tried several "solutions" online but it seems that none really worked. I tried removing all the drivers and reverting back to the old ones in Pop Shop, purging and re-installing 535 from Pop Shop, and purging and re-installing 535 from the Nvidia driver site.
I receive no errors from Pop Shop but if I try to install it from the .run file I get these errors:
Error "Building kernel modules" Error "Checking to see whether the nvidia kernel module was successfully built" ERROR: The nvidia kernel module was not created. Installation has FailedHere is my first warning that the compiler check failed:
Later the errors start happening and keep on coming:
I am not sure what I need to look for to fix. Has anyone else had an issue like this before? Any advice would be appreciated. Thanks in advance.
After upgrading to version 22.04 (from 20.04) I get an error message whenever I try to install/update packages regarding a list of unconfigured packages. I tried issuing dkpg --configure -a, even removing and reinstalling these packages, but I can't resolve this problem.
I removed all installed versions of gcc, g++, cpp, and even build-essential, made sure that there are no errors, rebooted the system, but when I install build-essential I get the same error message.
The error message is:
Setting up cpp (4:11.2.0-1ubuntu1) ...
update-alternatives: error: alternative cpp can't be master: it is a slave of gcc
dpkg: error processing package cpp (--configure):
installed cpp package post-installation script subprocess returned error exit s
tatus 2
dpkg: dependency problems prevent configuration of x11-xserver-utils:
x11-xserver-utils depends on cpp; however:
Package cpp is not configured yet.
dpkg: error processing package x11-xserver-utils (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of gcc:
gcc depends on cpp (= 4:11.2.0-1ubuntu1); however:
Package cpp is not configured yet.
dpkg: error processing package gcc (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of xorg:
xorg depends on x11-xserver-utils; however:
Package x11-xserver-utils is not configured yet.
dpkg: error processing package xorg (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of g++:
g++ depends on cpp (= 4:11.2.0-1ubuntu1); however:
Package cpp is not configured yet.
g++ depends on gcc (= 4:11.2.0-1ubuntu1); however:No apport report written beca
use the error message indicates its a followup error from a previous failure.
No
apport report written because the error message indicates its a followup error f
rom a previous failure.
No apport report written because MaxReports is reached al
ready
Package gcc is not configured yet.
dpkg: error processing package g++ (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of gdm3:
No apport report written because MaxReports is reached already
gdm3 depends on x
11-xserver-utils; however:
Package x11-xserver-utils is not configured yet.
dpkg: error processing package gdm3 (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
dpkg: dependency p
roblems prevent configuration of build-essential:
build-essential depends on gcc (>= 4:10.2); however:
Package gcc is not configured yet.
build-essential depends on g++ (>= 4:10.2); however:
Package g++ is not configured yet.
dpkg: error processing package build-essential (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
dpkg: dependency p
roblems prevent configuration of ubuntu-desktop-minimal:
ubuntu-desktop-minimal depends on gdm3; however:
Package gdm3 is not configured yet.
ubuntu-desktop-minimal depends on xorg; however:
Package xorg is not configured yet.
dpkg: error processing package ubuntu-desktop-minimal (--configure):
dependency problems - leaving unconfiguredim not tech savvy so please be patient with me:). So a sudo apt upgrade broke my system, specifically i could not use nvidia drivers anymore. Searching here and there I did sudo apt purge *nvidia* and tried installing the older nvidia driver again but same error happens as when I tried upgrading .
Errors were encountered while processing: nvidia-dkms-470 nvidia-driver-470 E: Sub-process /usr/bin/dpkg returned an error code (1)
So the make log file in /var/lib/dkms/nvidia/470.63.01/build/make.log showed:
warning: the compiler differs from the one used to build the kernel The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0 You are using: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
gcc-12 is already installed, I dont know what i am doing wrong ? :(