CentOS7升级binutils

  binutils官网:https://www.gnu.org/software/binutils/

  binutils源码下载地址:https://ftp.gnu.org/gnu/binutils/

(1).实验环境

  4核8G  CentOS7.9.2009

  配置了阿里云yum源和阿里云epel源,关闭防火墙,关闭SELinux。

(2).yum安装

  CentOS7已于2024年6月30日停止维护,导致官方的软件源(mirrorlist.centos.org)无法访问,所以我们要更换国内的镜像源(例如阿里云或清华源)。

  1、我这里使用阿里云的SCL仓库。

[root@localhost ~]# cd /etc/yum.repos.d/
# 如果有SCL的yum源,则备份原文件(以防万一)
[root@localhost yum.repos.d]# mv CentOS-SCLo-scl.repo CentOS-SCLo-scl.repo.bak 2>/dev/null
[root@localhost yum.repos.d]# mv CentOS-SCLo-scl-rh.repo CentOS-SCLo-scl-rh.repo.bak 2>/dev/null
#创建指向阿里云的SCL的yum源文件
[root@localhost yum.repos.d]# vim CentOS-SCLo-scl.repo
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  
[root@localhost yum.repos.d]# vim CentOS-SCLo-scl-rh.repo
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
  
#下载GPG密钥,这个是官网地址
[root@localhost yum.repos.d]# curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo
#导入密钥到RPM库
[root@localhost yum.repos.d]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
#清除缓存并重新加载
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache

  2、yum安装前可以看下阿里云的SCL仓库支持版本:https://mirrors.aliyun.com/centos/7/sclo/x86_64/,binutils就支持devtoolset-7~devtoolset-11版本。

#安装devtoolset-11版的binutils
[root@localhost yum.repos.d]# yum -y install devtoolset-11-binutils

  3、此时还需要激活,否则binutils还是使用的老版本

[root@localhost yum.repos.d]# ld --version
GNU ld version 2.27-44.base.el7
Copyright (C) 2016 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
#临时激活devtoolset-11软件集合,一旦重启就会失效
#也可以用source /opt/rh/devtoolset-11/enable来进行激活,这个命令写入环境变量就可以持久化
[root@localhost yum.repos.d]# scl enable devtoolset-11 bash
[root@localhost yum.repos.d]# ld --version
GNU ld version 2.36.1-1.el7.2
Copyright (C) 2021 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

  4、持久化激活

[root@localhost yum.repos.d]# echo "source /opt/rh/devtoolset-11/enable" >> /etc/profile

(3).源码编译升级

  1、安装依赖包

[root@localhost ~]# yum -y install gcc gcc-c++

  2、编译安装binutils

[root@localhost ~]# tar xvf binutils-2.45.tar.xz
[root@localhost ~]# cd binutils-2.45
[root@localhost binutils-2.45]# mkdir tmp && cd tmp
[root@localhost tmp]# ../configure --prefix=/usr/local/binutils-2.45
[root@localhost tmp]# echo $?
0
[root@localhost tmp]# make -j$(nproc)
[root@localhost tmp]# echo $?
0
[root@localhost tmp]# make install
[root@localhost tmp]# echo $?
0

  3、配置环境变量

[root@localhost tmp]# echo "export PATH=/usr/local/binutils-2.45/bin${PATH:+:${PATH}}" >> /etc/profile
[root@localhost tmp]# source /etc/profile

  

posted @ 2026-01-28 17:37  苦逼运维  阅读(2)  评论(0)    收藏  举报