刪除update-alternatives
中舊的gcc和g++配置:
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
安裝
it seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. however, we can explicitly install the following packages:
sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4
或者安裝gcc9 gcc10
sudo apt-get install gcc-9 gcc-9 g++-9 g++-10
symbolic links cc and c++ are installed by default. we will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)
如果前面安裝的是 gcc9, g++9 , 自行修改下面命令中的版本即可, 並將預設使用的版本設定為高的優先順序
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
configure alternatives
the last step is configuring the default commands for gcc, g++. it』s easy to switch between 4.3 and 4.4 interactively:
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
or switch using script:
#!/bin/sh
if [ -z "$1" ]; then
echo "usage: $0 version" 1>&2
exit 1
fiif [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then
echo "no such version gcc/g++ installed" 1>&2
exit 1
fiupdate-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
安裝多個版本的gcc
1.安裝 低版本安裝參見 高版本 比如gcc8.3 安裝 yum install centos release scl y yum install devtoolset 8 y 2.設定相應版本gcc路徑 gcc8.3的環境變數設定檔案是在 vim opt rh devtoolset 8 enabl...
ubuntu安裝多個版本的gcc
最近做源 分析需要用到低版本的gcc,但是原系統已經有了高版本的gcc。現記錄一下怎麼安裝多個版本的gcc 檔案放在 home lu gcc資料夾下然後解壓 cd home lu gcc tar zxvf gcc 4.6.2.tar.gz mkdir gcc build 這一步很重要,要不然會報錯 ...
linux安裝多個python版本方法
有些linux系統原本以及安裝了python,涉及到很多系統命令不能刪除。而這個python版本並不是我們想要的。step 1 檢視版本 python step 2 檢視安裝位置 which python step3 安裝依賴包 yum y groupinstall development tool...