CentOS 7 安装

CentOS 7 是一款经典的 RedHat 系 Linux 发行版。虽然现在已经老掉牙了,但是偶尔还能看见它们的身影。

安装

下载 CentOS-7-x86_64-DVD-2207-02.iso,这是一个包含了截至 2022 年 7 月的所有更新和补丁的映像。

What is the difference between CentOS "DVD" vs "Everything" ISOs | Super User

新建并启动虚拟机。在第一个配置页中,启用网络接口并记下 IP 地址,然后点击开始安装。

image

在第二个配置页中,创建用户帐户,设置密码,并设置为管理员,然后点 Done。

image

换源

成功安装并启动 CentOS 后,在本地主机使用 SSH 和刚刚记下的 IP 地址连入 CentOS。由于 CentOS 7 默认的软件源已经停止维护了,因此要为 CentOS 7 的包管理工具 yum 换源。

首先查看 CentOS 版本号。如果你按照上面的步骤安装了 CentOS,那么你的版本号应该为 7.9.2009

$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

接下来运行下面的命令换源。如果你的版本号和我不同,记得替换下面的 7.9.2009 为你自己的版本号。

  • 官方源:

    sudo sed -e "s/mirror.centos.org/vault.centos.org/g" \
             -e "s/^#.*baseurl=http/baseurl=http/g" \
             -e "s/^mirrorlist=http/#mirrorlist=http/g" \
             -i.bak \
             /etc/yum.repos.d/CentOS-*.repo
    
  • 清华源:

    sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
             -e "s|^#.*baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009|g" \
             -e "s|^#.*baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009|g" \
             -i.bak \
             /etc/yum.repos.d/CentOS-*.repo
    
  • 恢复原配置:

    for file in /etc/yum.repos.d/*.bak; do
        ori="${file%.bak}"
        sudo mv "$file" "$ori"
    done
    

接下来更新软件包缓存:

yum makecache

参考:CentOS Vault 软件仓库 | 清华大学开源软件镜像站

现代环境配置

扩展仓库

CentOS 7 是一个老掉牙的系统,其软件源提供的默认软件一样老掉牙。可以安装扩展库为它换血:

  • EPEL:Fedora 维护的额外软件包仓库
  • SCL:为 CentOS 提供软件包的多个版本
sudo yum install -y centos-release-scl epel-release

换源:

sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
         -e "s|^#.*baseurl=http://mirror.centos.org/centos/7/sclo/\$basearch|baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009/sclo/x86_64|g" \
         -i.bak \
         /etc/yum.repos.d/CentOS-SCLo-scl*.repo

yum makecache

安装 GCC 11

sudo yum install -y devtoolset-11

将下面这行加入 ~/.bashrc

source /opt/rh/devtoolset-11/enable

参考:How to properly upgrade gcc on Centos 7? | Super User

安装开发套件

sudo yum groupinstall -y "Development tools"
posted @ 2024-10-18 10:47  Undefined443  阅读(320)  评论(0)    收藏  举报