Debian/Ubuntu添加PPA源安装gcc多版本

xingyun86 2020-9-8 2253

Debian/Ubuntu安装gcc7/gcc8/gcc9时,查相关教程需要添加PPA源进行安装

sudo apt install build-essential
sudo apt install software-properties-common
sudo apt install apt-transport-https
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-7 g++-7 gcc-8 g++-8 gcc-9 g++-9

但进行安装时总是连接错误,在知乎以及其他博客上查阅相关资料后,终于找到了解决办法。

添加ppa时,会在/etc/apt/sources.list.d目录下创建list文件。本人使用ustc镜像,找到目录下ppa所创建的list文件,打开将其中的链接

deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main

修改为:

deb https://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu xenial main

其中http需要改为https,否则仍将连接失败。

过后进行update再进行安装即可。

以下命令将为每个版本配置替代方案并将优先级与其关联。 默认版本是具有最高优先级的版本,在我们的例子中是gcc-9。

# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9
# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8
# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7

稍后如果要更改默认版本,请使用update-alternatives命令:

sudo update-alternatives --config gcc


期间可能遇到的问题及解决方案

gpg: no valid OpenPGP data found

解决方案如下:

Remove the Ethereum repository first:

sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
sudo apt update

Remove imported GPG key:

sudo apt-key del 1E9377A2BA9EF27F

Import GPG key of the Ethereum repo again:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F

Add repository again:

sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update

UPDATE

Remove the Ethereum repository again:

sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
sudo apt update

Remove imported GPG key:

sudo apt-key del 1E9377A2BA9EF27F

Try

gpg --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F

and next

gpg --export --armor 1E9377A2BA9EF27F | sudo apt-key add -

Add repository for Debian/Ubuntu:(这里最好还是改成上面的https,下载速度快)

echo -e "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-groovy.list

Update apt:

sudo apt update

Install software you want from the ppa:ubuntu-toolchain-r repository.


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回