GCC 版本 4.9 没有安装候选

GCC version 4.9 has no installation candidate

我正在尝试在 Ubuntu 上安装 gcc 版本 4.9 以替换当前版本 7.5(因为 Torch 与版本 6 及更高版本不兼容)。但是,即使按照精确的说明进行操作,我也无法安装它。我做到了:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo aot-get remove gcc
sudo apt-get install gcc-4.9.

请注意,我已经安装了 CUDA。当我尝试安装 4.9 版时,它给出了这个:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'gcc-4.9-hppa-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-m68k-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-sh4-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-mips64el-linux-gnuabi64' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-aarch64-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-hppa64' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-sparc-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-powerpc-linux-gnuspe' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-s390x-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-arm-linux-gnueabihf' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-mips64-linux-gnuabi64' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-powerpc64le-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-powerpc-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-powerpc64-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-sparc64-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-mipsel-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-alpha-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-mips-linux-gnu' for regex 'gcc-4.9.'
Note, selecting 'gcc-4.9-arm-linux-gnueabi' for regex 'gcc-4.9.'
The following packages were automatically installed and are no longer required:
  cuda-cudart-10-2 cuda-cudart-dev-10-2 cuda-cufft-10-2 cuda-cufft-dev-10-2
  cuda-cuobjdump-10-2 cuda-curand-10-2 cuda-curand-dev-10-2 cuda-cusolver-10-2
  cuda-cusolver-dev-10-2 cuda-cusparse-10-2 cuda-cusparse-dev-10-2
  cuda-driver-dev-10-2 cuda-gdb-10-2 cuda-libraries-10-2
  cuda-libraries-dev-10-2 cuda-license-10-2 cuda-memcheck-10-2
  cuda-misc-headers-10-2 cuda-npp-10-2 cuda-npp-dev-10-2 cuda-nsight-10-2
  cuda-nsight-compute-10-2 cuda-nsight-systems-10-2 cuda-nvdisasm-10-2
  cuda-nvgraph-10-2 cuda-nvgraph-dev-10-2 cuda-nvjpeg-10-2
  cuda-nvjpeg-dev-10-2 cuda-nvml-dev-10-2 cuda-nvprof-10-2 cuda-nvprune-10-2
  cuda-nvrtc-10-2 cuda-nvrtc-dev-10-2 cuda-nvtx-10-2 cuda-nvvp-10-2
  cuda-sanitizer-api-10-2 cuda-visual-tools-10-2 freeglut3-dev g++-7
  libcublas-dev libcublas10 libnvidia-extra-440 libxi-dev libxmu-dev
  libxmu-headers libxt-dev nsight-compute-2019.5.0 nsight-systems-2019.5.2
  nvidia-compute-utils-440 nvidia-kernel-common-440 nvidia-kernel-source-440
  nvidia-modprobe nvidia-utils-440 xserver-xorg-video-nvidia-440
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

不管什么原因,它不想安装它。另一方面,当我键入 sudo apt-get install gcc 时,它只会重新安装 7.5 版。 我该怎么做才能用 4.9 版替换 GCC(和 G++)?

与此同时,我想通了自己。但是您必须补充一点,奇怪的是,G++ 和 GCC 4.9 版仍然不可用,您必须使用 4.8。通过结合多个来源,我构建了一种在您的机器上安装 G++ 和 GCC 4.8.5 并将它们配置为默认值的方法:

# Remove old packages and install new ones
sudo apt-get remove gcc g++
sudo apt-get install gcc-4.8 g++-4.8 build-essential
# After this however, you can only access it with specifically calling for 'gcc-4.8' and 'g++-4.8'. So we set them default
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
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++

当我们现在键入 gcc --version 时,我们得到:

gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GCC 4.9 repo 仍然可以正式使用,只需将这些添加到您的 repo

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

然后重新更新安装。

更具体的 A2:

1.su root,修改/etc/apt/sources.list 添加

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

2.update来源

sudo apt-get update

3.install

sudo apt-get install gcc-4.9