乐趣区

关于linux:centos7安装升级切换gcc

装置 gcc

yum install gcc
yum install gcc-c++

降级 gccx.x.x

wget https://ftp.gnu.org/gnu/gcc/gcc-x.x.x....
tar -xzvf gcc-x.x.x.tar.gz
cd gcc-x.x.x
./contrib/download_prerequisites
mkdir build
cd build
../configure --prefix=/usr/local/gccx.x.x --enable-languages=c,c++ --disable-multilib
make -j4
make install
gcc -v

查找所有 gcc 版本

find /usr -name gcc  

切换 gcc 版本

to 4.8.5
mkdir -p /usr/local/bin/gcc-9.3.0
mv /usr/bin/gcc /usr/local/bin/gcc-9.3.0/
ln -s /usr/local/gcc4.8.5/bin/gcc /usr/bin/gcc

mkdir -p /usr/local/bin/g++-9.3.0
mv /usr/bin/g++ /usr/local/bin/g++-9.3.0/
ln -s /usr/local/gcc4.8.5/bin/g++ /usr/bin/g++

mkdir -p /usr/local/bin/c++-9.3.0
mv /usr/bin/c++ /usr/local/bin/c++-9.3.0/
ln -s /usr/local/gcc4.8.5/bin/c++  /usr/bin/c++

to 9.3.0
mkdir -p /usr/local/bin/gcc-4.8.5
mv /usr/bin/gcc /usr/local/bin/gcc-4.8.5/
mv /usr/local/bin/gcc-9.3.0/gcc  /usr/bin/gcc

mkdir -p /usr/local/bin/g++- 4.8.5
mv /usr/bin/g++ /usr/local/bin/g++-4.8.5/
mv /usr/local/bin/g++-9.3.0/g++  /usr/bin/g++

mkdir -p /usr/local/bin/c++- 4.8.5
mv /usr/bin/c++ /usr/local/bin/c++-4.8.5/
mv /usr/local/bin/c++-9.3.0/c++  /usr/bin/c++

to 8.2.0
mkdir -p /usr/local/bin/gcc-4.8.5
mv /usr/bin/gcc /usr/local/bin/gcc-4.8.5/
ln -s /usr/local/gcc8.2.0/bin/gcc  /usr/bin/gcc

mkdir -p /usr/local/bin/g++-4.8.5
mv /usr/bin/g++ /usr/local/bin/g++-4.8.5/
ln -s /usr/local/gcc8.2.0/bin/g++  /usr/bin/g++

mkdir -p /usr/local/bin/c++-4.8.5
mv /usr/bin/c++ /usr/local/bin/c++-4.8.5/
ln -s /usr/local/gcc8.2.0/bin/c++  /usr/bin/c++
退出移动版