在 Ubuntu 21.04 上安裝 gcc/g++ 6

在 Ubuntu 21.04 上安裝 gcc/g++ 6

我正在嘗試編譯 Cuda 10.2,預計 gcc-10 將無法編譯它。使用 20.04 時很簡單,新增仿生儲存庫、更新、安裝、更新替代方案。使用 21.04 我無法讓任何東西工作。

我嘗試使用 xenial 和 bionic 'main' 和 'universe' 儲存庫,這會引發有關 PUBKEY 的錯誤。我從 ubuntu 密鑰伺服器獲取了 PUBKEY 並更新了軟體包列表,沒有錯誤。

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

來源.列表->

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

有誰知道我如何使用 Ubuntu 21.04 來實現這一目標?我讀過的每篇文章都說要新增 bionic 或 xenial 儲存庫、更新、安裝。到目前為止我還沒有運氣。

答案1

我透過瀏覽 Ubuntu 儲存庫取得了所需的軟體包 (.deb)這裡

以下是我手動安裝 gcc/g++ 6 所需的 .deb 軟體包清單。這假設您擁有編譯所需的大部分工具,並且只是希望切換預設的 gcc 版本。

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++

相關內容