Ubuntu20.04降级安装gcc、g++6

编译cuda9.1的程序时需要使用gcc6、g++6,如果直接使用命令sudo apt-get install gcc-6 g++-6 -y安装,会出现以下错误:

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 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

image

解决方法

第一步,添加软件源

sudo nano /etc/apt/sources.list

在文件末尾添加以下内容:

deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe

image

第二步,更新软件源、安装gcc6、g++6并将其设为高优先级(以后默认使用gcc6、g++6)

sudo apt update
sudo apt install gcc-6 g++-6 -y
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6
gcc -v

可以看到,这时候gcc、g++的默认版本已经变为6.4.0,安装成功!
image

posted @ 2022-10-12 19:53  云吱  阅读(2102)  评论(1编辑  收藏  举报