【Ubuntu20.04】安装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

要是不卸载:
使用update-alternatives命令设置默认编译器版本。首先列出已安装的GCC版本:

sudo update-alternatives --list gcc

使用update-alternatives命令设置gcc和g++的符号链接到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

最后,使用update-alternatives命令配置默认的GCC版本为GCC 11:

sudo update-alternatives --config gcc

猜你喜欢

转载自blog.csdn.net/x1131230123/article/details/132544277
今日推荐