CentOS 7.6
The method of upgrading gcc/g++ may not be applicable to other linux systems
1. View version
g++ -v
gcc -v
Currently checking the version, it is found that 4.8.5
this is already an old version in 2015, and c++11
the support for it is not very perfect. In order to facilitate learning and writing new version codes, it is still possible to upgrade
If you don't have gcc/g++ on your system, try to install it with the following method
yum install -y gcc gcc-c++
example
[root@bt-7274:~]# yum install -y gcc gcc-c++
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* centos-sclo-rh: ftp.sjtu.edu.cn
* centos-sclo-sclo: ftp.sjtu.edu.cn
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package gcc-c++-4.8.5-44.el7.x86_64 already installed and latest version
Nothing to do
2. Upgrade
yum list dev\*gcc
Use this command to see which versions can be installed
You can see that the latest version is already 11, so let's install the latest version directly
yum install devtoolset-11-gcc devtoolset-11-gcc-c++
Installed:
devtoolset-11-gcc.x86_64 0:11.2.1-9.1.el7 devtoolset-11-gcc-c++.x86_64 0:11.2.1-9.1.el7
Dependency Installed:
devtoolset-11-binutils.x86_64 0:2.36.1-1.el7.2 devtoolset-11-libstdc++-devel.x86_64 0:11.2.1-9.1.el7 devtoolset-11-runtime.x86_64 0:11.1-2.el7
Complete!
If you see it complete
, it means the installation is over
3. Take effect
All you have to do now is for the newly installed version to take effect
source /opt/rh/devtoolset-11/enable
However, doing so can only take effect in the current bash, and you will find that it is still the case if you create a new bash 4.8.5
. What to do is to write this statement into the configuration file of bashrc, so that it will be executed automatically every time a new bash is created.
To modify /etc/bashrc
, it is strongly recommended to make a backup before modifying
cp /etc/bashrc ~/bashrc.bak
Then execute the following two commands
echo "source /opt/rh/devtoolset-11/enable" >> /etc/bashrc
source /etc/bashrc
It’s OK now, create a new bash, and gcc -v
find that it’s a new version
4. About man invalidation
After the version is upgraded, the man manual may become invalid. This is because the environment variable of man has been modified
# echo $MANPATH
/opt/rh/devtoolset-11/root/usr/share/man
If you need to use the man command, you also need to re-modify MANPATH
the environment variable
export MANPATH=/usr/share/man
Solve the solution that the reference man can't find anything