【linux】GCC 7和GCC 8版本不再包含在默认的软件仓库中

由于GCC 7和GCC 8版本不再包含在默认的软件仓库中,不能直接通过apt install gcc-7apt install gcc-8命令来安装这些版本。不过,可以通过添加Ubuntu 20.04(Focal Fossa)的软件仓库到系统来安装这些较旧的GCC版本,因为GCC 7和GCC 8在Ubuntu 20.04的仓库中仍然可用。

以下是安装GCC 7和GCC 8的步骤:

  1. 添加Ubuntu 20.04的软件仓库
    打开/etc/apt/sources.list文件,并添加以下行:
bash 复制代码
 deb [arch=amd64] http://archive.ubuntu.com/ubuntu focal main universe

这将让系统知道去哪里查找Ubuntu 20.04的软件包。

  1. 更新软件包列表
    添加了新的软件仓库后,你需要更新你的软件包列表:
bash 复制代码
  sudo apt update
  1. 安装GCC 7和GCC 8

    现在你可以安装GCC 7和GCC 8了:

    bash 复制代码
    sudo apt install gcc-7 g++-7 gcc-8 g++-8
  2. 配置更新替代方案 (可选):(没有使用)

    置默认的GCC版本,可以使用update-alternatives

bash 复制代码
  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80
  sudo update-alternatives --config gcc

这将选择默认的GCC版本。

  1. 验证安装
    安装完成后,使用以下命令来验证GCC 7和GCC 8是否正确安装:
bash 复制代码
  gcc-7 --version
  gcc-8 --version
bash 复制代码
 (base) ~$ gcc-7 --version
gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 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.

(base) ~$ gcc-8 --version
gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0
Copyright (C) 2018 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.
  1. 查看系统安装的gcc版本
bash 复制代码
dpkg -l | grep gcc

我的系统中安装的版本:

bash 复制代码
(base) ~$ dpkg -l | grep gcc
ii  gcc                                        4:9.3.0-1ubuntu2                      amd64        GNU C compiler
ii  gcc-10-base:amd64                          10.5.0-1ubuntu1~20.04                 amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-10-base:i386                           10.5.0-1ubuntu1~20.04                 i386         GCC, the GNU Compiler Collection (base package)
ii  gcc-7                                      7.5.0-6ubuntu2                        amd64        GNU C compiler
ii  gcc-7-base:amd64                           7.5.0-6ubuntu2                        amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-8                                      8.4.0-3ubuntu2                        amd64        GNU C compiler
ii  gcc-8-base:amd64                           8.4.0-3ubuntu2                        amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-9                                      9.4.0-1ubuntu1~20.04.2                amd64        GNU C compiler
ii  gcc-9-base:amd64                           9.4.0-1ubuntu1~20.04.2                amd64        GCC, the GNU Compiler Collection (base package)
ii  libgcc-7-dev:amd64                         7.5.0-6ubuntu2                        amd64        GCC support library (development files)
ii  libgcc-8-dev:amd64                         8.4.0-3ubuntu2                        amd64        GCC support library (development files)
ii  libgcc-9-dev:amd64                         9.4.0-1ubuntu1~20.04.2                amd64        GCC support library (development files)
ii  libgcc-s1:amd64                            10.5.0-1ubuntu1~20.04                 amd64        GCC support library
ii  libgcc-s1:i386                             10.5.0-1ubuntu1~20.04                 i386         GCC support library
ii  libuno-cppuhelpergcc3-3                    1:6.4.7-0ubuntu0.20.04.12             amd64        LibreOffice UNO runtime environment -- CPPU helper library
ii  libuno-purpenvhelpergcc3-3                 1:6.4.7-0ubuntu0.20.04.12             amd64        LibreOffice UNO runtime environment -- "purpose environment" helper
ii  libuno-salhelpergcc3-3                     1:6.4.7-0ubuntu0.20.04.12             amd64        LibreOffice UNO runtime environment -- SAL helpers for C++ library

请注意,添加旧版本的软件仓库可能会让系统暴露在安全风险中,因为旧版本的软件包可能不会接收到安全更新。因此,只有在确实需要旧版本的GCC时才推荐这样做,并且在完成工作后,最好移除旧的软件仓库以避免将来的依赖问题。

相关推荐
IT研究所1 天前
IT 资产管理 (ITAM) 与 ITSM 协同实践:构建从资产到服务的闭环管理体系
大数据·运维·人工智能·科技·安全·低代码·自动化
Codefengfeng1 天前
分辨压缩包的真加密与伪加密
linux·运维·网络
014.1 天前
2025最新jenkins保姆级教程!!!
java·运维·spring boot·spring·jenkins
leifengzhy1 天前
Jenkins使用pipeline和maven创建项目
运维·jenkins·maven
码农阿豪1 天前
Jenkins Git 克隆失败深度解析:从 “Connection reset by peer“ 到彻底解决
运维·git·jenkins
暴力求解1 天前
Linux---进程(五)进程调度
linux·运维·服务器
楼田莉子1 天前
C++项目:日志&&线程池
linux·c++·学习·visual studio code
wsad05321 天前
Linux 用户和组管理完整指南(中英文参数对照)
linux·运维·服务器
S-码农1 天前
Linux进程通讯——共享内存
linux
EmbedLinX1 天前
嵌入式Linux之U-Boot
linux·服务器·笔记·学习