0%

后CentOS7时代如何用上gcc9

CentOS7在2024年6月30日停止更新,其repo源也随之down掉了,导致我在用去年12月的方法升级gcc的时候报错:Could not resolve host: mirrorlist.centos.org; Name or service not known

运行命令如下:

1
2
yum install centos-release-scl -y 
yum install devtoolset-9 devtoolset-9-runtime -y

第一反应尝试给yum换源,找了网上几个换阿里源的方法,第一行没问题了,第二行报错找不到devtoolset-9。

为此又学了yum repo的结构,存储在/etc/yum.repos.d/下面所有的.repo里边写的都是源,enabled=1就是开着。搜了半天又发现这个devtoolset-9一般在CentOS-SCLo-scl.repo,CentOS-SCLo-scl-rh.repo这两个源里边找(这两个源就是通过第一句yum install centos-release-scl自动配置的)。

手动换一下清华源吧,把这两个文件里enabled的baseurl都打开,mirrorlist都关上,然后换成清华源的对应目录,原理如下:

1
2
3
4
5
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/版本|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/版本|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

其实就是把原来的centos.org换成tuna.tsinghua.edu.cn。

换了还不行,一看目录里根本没有devtoolset 9,只有45678,以为清华源东西不全。没想到又踩了坑,原来我用的CentOS 7.6.1810,源里就没有9,得超前几个版本才有。

换7.8.2003的源,问题解决。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# CentOS-SCLo-sclo.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.8.2003/sclo/$basearch/sclo/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-testing]
name=CentOS-7 - SCLo sclo Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-source]
name=CentOS-7 - SCLo sclo Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/sclo/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-debuginfo]
name=CentOS-7 - SCLo sclo Debuginfo
baseurl=http://mirrors.aliyun.com/centos-debuginfo/centos/7/sclo/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

PS: 下次要go build obfs4的时候别忘了,go build不起来也有可能是gcc的问题。