CentOS 7.3 gcc 升级到 4.9.4

环境

系统 CentOS 7.3 1611
需求 使用 rpm 安装 nodeJS 时提示自带的 gcc 4.8.5 版本太低,最低要 4.9.4
服务器又没有公网,只能手动装了。。。

安装资源

上传到 CSDN 了,之后会补上网盘链接
补上百度网盘链接,无私分享,但愿当你觉得这篇文章有用时不会因为找资源浪费时间
提取码:p0ri

安装

下载源码包后通过 winscp 等工具将六个源码包上传到服务器

解压

将其中的 gcc-4.9.4.tar.bz2 解压

# 解压
tar -jxvf gcc-4.9.4.tar.bz2

# 进入文件夹
cd gcc-4.9.4

添加依赖包

下一步应该执行 ./contrib/download_prerequisites,但是由于没有公网,所以自动下载的五个依赖包无法下载,所以需要修改文件,将其中的五个 wget 行注释掉,注意:把 mpc 的版本修改成 1.0.3

开头下载好的文件除去 gcc-4.9.4.tar.bz2 还剩五个,分别是:
cloog-0.18.1.tar.gz
gmp-4.3.2.tar.bz2
isl-0.12.2.tar.bz2
mpc-1.0.3.tar.gz
mpfr-2.4.2.tar.bz2
将这五个源码包移动到 gcc 根目录,并执行

./contrib/download_prerequisites 

生成 Makefile 文件

创建与 gcc 根目录平级的临时目录

cd ..
mkdir build-gcc
cd build-gcc
../gcc-4.9.4/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

编译

make -j 8

-j 利用多核处理器加快速度,选择 8 核

安装

make install

完成提示

Libraries have been installed in:
    /usr/local/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
        during execution
    - add LIBDIR to the `LD_RUN_PATH' environment variable
        during linking
    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
    - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

重启

reboot

问题

本来到这就结束了,然后我查看版本

gcc -v

发现还是 4.8.5,诶,不对啊!
我查了半天资料,网上有说配置文件设置路径的,有说加载动态文件的,试了一下都不行啊。

最后我才想起来我好像用 yum 升级过,由于公司服务器提供的 yum 源只有基本的 iso 资源,所以只能更新到 4.8.5,而 CentOS 7.3 自带的是 4.8.2.

然后卸载 gcc 4.8.5 就行了。

查看安装的版本

[szq@localhost software]$ rpm -q gcc
gcc-4.48.5-23.el6.x86_64

卸载

rpm -e gcc-4.48.5-23.el6.x86_64

发现报错,提示有些软件依赖 gcc 或者 gcc 依赖这些软件,所以要先卸载提示的软件,然后再卸载 gcc。

验证

gcc -v

这回就提示 4.9.4

大功告成

撒花~

猜你喜欢

转载自blog.csdn.net/weixin_41474364/article/details/102907305