第一种方法:
安装的是13.04版本的ubuntu.
sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib
sudo rm -rf /usr/bin/gcc /usr/bin/g++
sudo ln -s /usr/bin/gcc-4.4 /usr/bin/gcc
sudo ln -s /usr/bin/g++-4.4 /usr/bin/g++
gcc –v 如果输出如下显示的版本号(4.4.7),说明降低版本成功
在14.04版本ubuntu下,gcc版本为4.8,第一种办法无法实现.采用如下方法:
<span style="font-size: 13.3333px; font-family: Arial, Helvetica, sans-serif;">wfly@ubuntu:~/linux-3.2$ <span style="color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(234, 247, 253);">sudo apt-get install gcc-4.4</span></span>
<span style="font-size: 13.3333px; font-family: Arial, Helvetica, sans-serif;">wfly@ubuntu:~/linux-3.2$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40 </span><span style="color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(234, 247, 253);">(这里“40” 是优先级,值越大优先级越高)</span>
<span style="font-size: 13.3333px; font-family: Arial, Helvetica, sans-serif;">wfly@ubuntu:~/linux-3.2$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60</span><span style="font-size: 13.3333px; font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(234, 247, 253);">(本机自带的设置为60更高的优先级)</span>
wfly@ubuntu:~/linux-3.2$ sudo update-alternatives --config gcc There are 2 choices for the alternative gcc (providing /usr/bin/gcc). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/gcc-4.8 60 auto mode 1 /usr/bin/gcc-4.4 40 manual mode 2 /usr/bin/gcc-4.8 60 manual mode Press enter to keep the current choice[*], or type selection number: 1
<span style="color: rgb(70, 70, 70); font-family: simsun; font-size: 14px; line-height: 21px; background-color: rgb(234, 247, 253);">默认系统用最高优先级的, 这里我们选择1就可以了</span>
Using built-in specs. Target: i686-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.7-8ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --disable-libmudflap --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu Thread model: posix gcc version 4.4.7 (Ubuntu/Linaro 4.4.7-8ubuntu1)
如果想改为高版本的随时用update-alternatives --config 命令切换!