【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时才推荐这样做,并且在完成工作后,最好移除旧的软件仓库以避免将来的依赖问题。

相关推荐
real_haha3 小时前
Fabric 学习资料总结 持续更新
运维·fabric
caijingshiye5 小时前
九科信息企业自动化智能体:打破知行割裂,让AI真正动手干活
运维·人工智能·自动化
HIT_Weston7 小时前
26、【Ubuntu】【远程开发】内网穿透:密钥算法介绍(二)
linux·运维·ubuntu
zl_dfq9 小时前
Linux第一个小程序 之 【进度条】
linux
wdfk_prog9 小时前
[Linux]学习笔记系列 -- [kernel]kthread
linux·笔记·学习
大地的一角9 小时前
(Linux)ELF格式与库的链接原理
linux·运维·服务器
z202305089 小时前
Linux之中断子系统-内核中断注册源码分析(4)
linux·运维·服务器
深思慎考9 小时前
微服务即时通讯系统(服务端)——用户子服务实现逻辑全解析(4)
linux·c++·微服务·云原生·架构·通讯系统·大学生项目
极小狐11 小时前
比 Cursor 更丝滑的 AI DevOps 编程智能体 - CodeRider-Kilo 正式发布!
运维·人工智能·devops
Sunlightʊə11 小时前
2.登录页测试用例
运维·服务器·前端·功能测试·单元测试