服务器非root安装gcc 4.8.5

时间:2023-12-24 16:11:19

1.下载gcc-4.8.5:

$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz

2.解压gcc:

$ tar zxvf gcc-4.8..tar.gz
$ cd gcc-4.8.

3.安装依赖三大件,会自动顺序安装gmp、mpfr、mpc

$ ./contrib/download_prerequisites

4.创建编译目录:

$ cd ..

$ mkdir gcc-4.8.-build
$ cd gcc-4.8.-build

5.编译并重置环境变量(不重置部分边境变量的话会报不能包含当前路径之类的错):

$ ../gcc-4.8./configure --prefix=/usr/local/gcc --enable-languages=c,c++ --build=x86_64-linux --disable-multilib
$ unset CPLUS_INCLUDE_PATH
$ unset LIBRARY_PATH

6.安装:

$ make -j8
$ make install

7.设置环境变量

#gcc
export LD_LIBRARY_PATH=/home/username/Programs/usr/lib64:/home/username/Programs/usr/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/home/username/Programs/usr/lib64:/home/username/Programs/usr/lib:$LIBRARY_PATH
export C_INCLUDE_PATH=/home/username/Programs/usr/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/home/username/Programs/usr/include:$CPLUS_INCLUDE_PATH
export PATH=/home/username/Programs/usr/bin:$PATH

注意:

1.部分环境变量需要重置,根据个人情况又不尽相同,一般是 LIBRARY_PATH, LD_LIBRARY_PATH, CPLUS_INCLUDE_PATH 等,不然会报如下错误:

[error] LIBRARY_PATH shouldn't contain the current directory

到时候对错误信息提到的环境变量 unset 就可以。

2.编译选项 --disable-multilib 问题:

如果不加此选项,make过程会出现莫名其妙的问题,大概是32 64位库的问题。