(1) 查看gcc以及g++的版本
gcc -v
g++ -v
star@ai:~ $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1) star@ai:~ $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.5.0-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1) star@ai:~ $
当前的版本是5.5
(2) 现在需要切换到6.0
首先安装gcc6.0
sudo apt-get install gcc-6.0
sudo apt-get install g++-6.0
(3) 进入/usr/bin 目录
ll 查看
lrwxrwxrwx 1 root root 14 10月 12 13:29 g++ -> /usr/bin/g++-5* -rwxr-xr-x 1 root root 13288 4月 23 2016 g3topbm* -rwxr-xr-x 1 root root 911744 4月 12 2018 g++-5* lrwxrwxrwx 1 root root 22 4月 24 13:16 g++-6 -> x86_64-linux-gnu-g++-6* lrwxrwxrwx 1 root root 22 7月 26 20:25 g++-7 -> x86_64-linux-gnu-g++-7* -rwxr-xr-x 1 root root 10232 2月 4 2018 gamma4scanimage* -rwxr-xr-x 1 root root 18504 9月 17 20:52 gapplication* -rwxr-xr-x 1 root root 277248 6月 22 17:27 gatttool* -rwxr-xr-x 1 root root 14376 3月 24 2018 gc* -rwxr-xr-x 1 root root 235600 4月 11 2018 gcalccmd* lrwxrwxrwx 1 root root 21 10月 12 10:18 gcc -> /etc/alternatives/gcc* -rwxr-xr-x 1 root root 907648 4月 12 2018 gcc-5* lrwxrwxrwx 1 root root 22 4月 24 13:16 gcc-6 -> x86_64-linux-gnu-gcc-6* lrwxrwxrwx 1 root root 22 7月 26 20:25 gcc-7 -> x86_64-linux-gnu-gcc-7* lrwxrwxrwx 1 root root 8 4月 7 2018 gcc-ar -> gcc-ar-7*
可以发现g++ 链接到g++-5*
(4) gcc版本切换
sudo rm gcc
sudo ln -s /usr/bin/gcc-6* gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 10
sudo rm g++
sudo ln -s /usr/bin/g++-6* g++
(5) 查看是否切换成功
lrwxrwxrwx 1 root root 14 8月 23 11:03 g++ -> /usr/bin/g++-6* -rwxr-xr-x 1 root root 13288 4月 23 2016 g3topbm* lrwxrwxrwx 1 root root 22 4月 24 13:16 g++-6 -> x86_64-linux-gnu-g++-6* lrwxrwxrwx 1 root root 22 4月 15 12:52 g++-7 -> x86_64-linux-gnu-g++-7* -rwxr-xr-x 1 root root 10232 2月 4 2018 gamma4scanimage* -rwxr-xr-x 1 root root 18504 9月 17 20:52 gapplication* -rwxr-xr-x 1 root root 277248 6月 22 17:27 gatttool* -rwxr-xr-x 1 root root 14376 3月 24 2018 gc* -rwxr-xr-x 1 root root 235600 4月 11 2018 gcalccmd* lrwxrwxrwx 1 root root 14 8月 23 11:03 gcc -> /usr/bin/gcc-6* -rwxr-xr-x 1 root root 907648 4月 12 04:17 gcc-5* lrwxrwxrwx 1 root root 22 4月 24 13:16 gcc-6 -> x86_64-linux-gnu-gcc-6* lrwxrwxrwx 1 root root 22 4月 15 12:52 gcc-7 -> x86_64-linux-gnu-gcc-7*
g++ -v
gcc -v
ln -s的用法
ln -s 原始文件 快捷方式(目标文件)