ToB企服应用市场:ToB评测及商务社交产业平台
标题:
gcc升级(含命令行升级、手动升级两种方式)
[打印本页]
作者:
魏晓东
时间:
2024-9-20 01:05
标题:
gcc升级(含命令行升级、手动升级两种方式)
1.yum源替换
默认yum源不可用,替换为国内源
替换前:
1.1 备份原始repo设置文件
cd /etc/yum.repos.d/
mkdir bak
mv CentOS-* bak/
复制代码
1.2 重新设置CentOS-Base.reporepo文件
若服务器有wget命令,可复制下述命令直接从互联网拉取阿里配置源到服务器
wget https://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
若服务器为最小化安装,没有wget命令,可以直接在/etc/yum.repos.d/目录下,创建名称为CentOS-Base.repo的文件,把下述内容复制到配置文件中
复制代码
CentOS-Base.reporepo全内容
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
修改后:
1.3 扫除缓存并重新创建
yum clean all
yum makecache
复制代码
2. gcc安装
yum -y install gcc gcc-c++
复制代码
安装后,默认版本为:4.8.5
3.命令行升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilse
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable">> /etc/profile
复制代码
执行过程中出现非常信息:
1.安装:centos-release-scl时正常,安装:devtoolset-9-gcc、devtoolset-9-gcc-c++、devtoolset-9-binutilse时出现报错
办理方法:
检察报错信息,报错为:CentOS-SCLo-scl-rh.repo文件地址无法访问
利用阿里对应的设置文件,修改改文件内容
CentOS-SCLo-scl-rh.repo文件全内容
[centos-sclo-rh]
name=CentOS-$releasever - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
CentOS-SCLo-scl.repo文件内容
[centos-sclo-sclo]
name=CentOS-$releasever - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/sclo/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
复制代码
2.扫除缓存,重新创建缓存后,再次安装devtoolset-9-gcc、devtoolset-9-gcc-c++、devtoolset-9-binutilse出现非常信息
办理方法:
检察报错信息为密钥题目,实验在安装时候,直接安装,不校验密钥
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilse --nogpgcheck
复制代码
乐成安装
在当前shell终端中使devtoolset-9见效,设置永世利用devtoolset-9,检察gcc版本,已经乐成升级到
9.3.1
4.手动升级
以
9.3.0
为例
4.1 安装包下载
# 创建存放目录
mkdir -p /apps/scripts
cd /apps/scripts/
# gcc安装包下载
下载地址:https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
可下载后上传,或直接在服务器上从互联网拉取
wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
复制代码
4.2 解压
tar -xzf gcc-9.3.0.tar.gz
cd gcc-9.3.0
复制代码
[root@rhel76 gcc-10.1.0]# mkdir build
[root@rhel76 gcc-10.1.0]# cd build/
[root@rhel76 build]# …/configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
复制代码
4.3 gcc升级
4.3.1 依靠拉取
cd /apps/scripts/gcc-9.3.0/
./contrib/download_prerequisites
// 在gcc-9.3.0目录下,多了gmp-6.1.0.tar.bz2、isl-0.18.tar.bz2、mpc-1.0.3.tar.gz、mpfr-3.1.4.tar.bz2四个压缩文件
// 若已经安装了bzip2命令,则会自动解压上述压缩包
// 演示环境为最小化安装,目前未安装bzip2命令
复制代码
4.3.2 gmp安装
解压gmp
cd /apps/scripts/gcc-9.3.0/
tar -xvjf gmp-6.1.0.tar.bz2
解压报错:
tar (child): bzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
复制代码
安装bzip2后,重新解压
安装bzip2
yum -y install bzip2 m4
// bzip2:解决上述报错 m4:解决configure过程中报错
继续安装gmp
tar -xvjf gmp-6.1.0.tar.bz2
cd /apps/scripts/gcc-9.3.0/gmp-6.1.0
./configure --prefix=/usr/local/gmp-6.1.0
make
make install
复制代码
解压完成
configure 完成
make完成
make install完成
4.3.3 mpfr安装
cd /apps/scripts/gcc-9.3.0/
tar -xvjf mpfr-3.1.4.tar.bz2
cd mpfr-3.1.4
./configure --prefix=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-6.1.0
make
make install
复制代码
解压完成
configure 完成
make完成
make install 完成
4.3.4 mpc安装
cd /apps/scripts/gcc-9.3.0/
tar -xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4
make
make install
复制代码
解压完成
configure 完成
make完成
make install 完成
4.3.5 gcc编译、安装
cd /apps/scripts/gcc-9.3.0
mkdir build
cd build/
../configure --prefix=/usr/local/gcc-9.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3
make
yum -y remove gcc gcc-c++
make install
复制代码
configure 完成
make完成–好久好久
build目次下对应文件巨细
旧版本删除完成
GCC安装完成
4.4 gcc命令设置
ln -s /usr/local/gcc-9.3.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-9.3.0/bin/g++ /usr/bin/g++
gcc -v
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4