【Ubuntu20.04】Install gcc11 g++11, Ubuntu18.04

#查看当前使用的gcc版本命令:
gcc -v
#更新软件源指令:
sudo apt-get update
#更新软件指令:
sudo app-get upgrade


# 添加相应的源
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
#更新软件源指令:
sudo apt-get update

# 卸载已有gcc
sudo apt remove gcc-9 g++-9
# 运行以下命令来清理已卸载软件包的残余文件和依赖项:
sudo apt autoremove

# 安装最新版gcc
sudo apt-get install gcc-11 g++-11

# 使用以下命令将/usr/bin/gcc符号链接指向GCC 11的路径:
sudo ln -s /usr/bin/gcc-11 /usr/bin/gcc
sudo ln -s /usr/bin/g++-11 /usr/bin/g++

#查看当前使用的gcc版本命令:
gcc -v

If not uninstalled:
Use the update-alternatives command to set the default compiler version. First list the installed GCC versions:

sudo update-alternatives --list gcc

Use the update-alternatives command to set up gcc and g++ symlinks to GCC 11:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g+±11 100

Finally, use the update-alternatives command to configure the default GCC version to GCC 11:

sudo update-alternatives --config gcc

Guess you like

Origin blog.csdn.net/x1131230123/article/details/132544277