red hat 如何使用yum命令安装gcc

  1. 挂载光盘  mount /dev/cdrom /mnt
    [root@localhost yum]# mount /dev/cdrom /mnt
    mount: /dev/sr0 is write-protected, mounting read-only
    

     

  2. 修改配置文件内容:
    [root@localhost mnt]# cd /usr/lib/python2.7/site-packages/yum
    [root@localhost yum]# ls
    callbacks.py   drpm.py          i18n.py            metalink.py      pgpmsg.py         rpmsack.py           updateinfo.py
    callbacks.pyc  drpm.pyc         i18n.pyc           metalink.pyc     pgpmsg.pyc        rpmsack.pyc          updateinfo.pyc
    comps.py       Errors.py        igroups.py         misc.py          pkgtag_db.py      rpmtrans.py          update_md.py
    comps.pyc      Errors.pyc       igroups.pyc        misc.pyc         pkgtag_db.pyc     rpmtrans.pyc         update_md.pyc
    config.py      failover.py      __init__.py        packageSack.py   plugins.py        sqlitesack.py        yumRepo.py
    config.pyc     failover.pyc     __init__.pyc       packageSack.pyc  plugins.pyc       sqlitesack.pyc       yumRepo.pyc
    constants.py   fssnapshots.py   logginglevels.py   packages.py      repoMDObject.py   sqlutils.py
    constants.pyc  fssnapshots.pyc  logginglevels.pyc  packages.pyc     repoMDObject.pyc  sqlutils.pyc
    depsolve.py    history.py       mdparser.py        parser.py        repos.py          transactioninfo.py
    depsolve.pyc   history.pyc      mdparser.pyc       parser.pyc       repos.pyc         transactioninfo.pyc
    [root@localhost yum]# vim yumRepo.py
    
  3.  
     //找到                  remote = url + '/' + relative 
     //修改成以下内容 /mnt 为你刚才挂载的目
     996 
     997             remote = "/mnt" + '/' + relative
     998 
    
  4. [root@localhost Packages]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# vim rhel-source.repo 
    
    #你可以备用你的这个配置文件。cp 文件名字 文件名字.bak 以防万一
    [Packages]
    #名字可以随便起
    name=Red Hat Linux
    #你刚才挂载光盘的目录
    baseurl=file:///mnt
    #设置为可用
    enabled=1
    #设置为不检查gpgcheck
    gpgcheck=0
    #这个是刚才挂载目录下的一个文件
    gpgkey=file:///mnt/RPM-GPG-KEY-redhat-beta
    

     

  5. [root@localhost yum.repos.d]# cd /mnt/Packages/
    [root@localhost Packages]# ll |grep gcc
    -r--r--r--  41 root root 10529884 Apr  1  2014 compat-gcc-44-4.4.7-8.el7.x86_64.rpm
    -r--r--r--  41 root root  6636564 Apr  1  2014 compat-gcc-44-c++-4.4.7-8.el7.x86_64.rpm
    -r--r--r--  77 root root 16816020 Apr  1  2014 gcc-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  75 root root  7497056 Apr  1  2014 gcc-c++-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  76 root root  6921348 Apr  1  2014 gcc-gfortran-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  75 root root 13538564 Apr  1  2014 gcc-gnat-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  75 root root  5999764 Apr  1  2014 gcc-objc-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  75 root root  6420436 Apr  1  2014 gcc-objc++-4.8.2-16.el7.x86_64.rpm
    -r--r--r--  79 root root    95916 Apr  1  2014 libgcc-4.8.2-16.el7.i686.rpm
    -r--r--r--  79 root root    88184 Apr  1  2014 libgcc-4.8.2-16.el7.x86_64.rpm
    

     从以下可以看到 安装gcc需要的依赖包很多自己一步一步安装比较麻烦所以可以直接使用yum解决包之间的依赖问题。

    [root@localhost Packages]# rpm -Uvh gcc-4.8.2-16.el7.x86_64.rpm 
    warning: gcc-4.8.2-16.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
    error: Failed dependencies:
    	cpp = 4.8.2-16.el7 is needed by gcc-4.8.2-16.el7.x86_64
    	glibc-devel >= 2.2.90-12 is needed by gcc-4.8.2-16.el7.x86_64
    	libmpc.so.3()(64bit) is needed by gcc-4.8.2-16.el7.x86_64
    	libmpfr.so.4()(64bit) is needed by gcc-4.8.2-16.el7.x86_64
    [root@localhost Packages]# yum -y install gcc-4.8.2-16.el7.x86_64.rpm 
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    Examining gcc-4.8.2-16.el7.x86_64.rpm: gcc-4.8.2-16.el7.x86_64
    Marking gcc-4.8.2-16.el7.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package gcc.x86_64 0:4.8.2-16.el7 will be installed
    --> Processing Dependency: cpp = 4.8.2-16.el7 for package: gcc-4.8.2-16.el7.x86_64
    Packages                                                                                                     | 4.1 kB  00:00:00     
    (1/2): Packages/group_gz                                                                                     | 134 kB  00:00:00     
    (2/2): Packages/primary_db                                                                                   | 3.4 MB  00:00:00     
    --> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.2-16.el7.x86_64
    --> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.2-16.el7.x86_64
    --> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.2-16.el7.x86_64
    --> Running transaction check
    ---> Package cpp.x86_64 0:4.8.2-16.el7 will be installed
    ---> Package glibc-devel.x86_64 0:2.17-55.el7 will be installed
    --> Processing Dependency: glibc-headers = 2.17-55.el7 for package: glibc-devel-2.17-55.el7.x86_64
    --> Processing Dependency: glibc-headers for package: glibc-devel-2.17-55.el7.x86_64
    ---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
    ---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
    --> Running transaction check
    ---> Package glibc-headers.x86_64 0:2.17-55.el7 will be installed
    --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-55.el7.x86_64
    --> Processing Dependency: kernel-headers for package: glibc-headers-2.17-55.el7.x86_64
    --> Running transaction check
    ---> Package kernel-headers.x86_64 0:3.10.0-123.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ====================================================================================================================================
     Package                       Arch                  Version                          Repository                               Size
    ====================================================================================================================================
    Installing:
     gcc                           x86_64                4.8.2-16.el7                     /gcc-4.8.2-16.el7.x86_64                 37 M
    Installing for dependencies:
     cpp                           x86_64                4.8.2-16.el7                     Packages                                5.9 M
     glibc-devel                   x86_64                2.17-55.el7                      Packages                                1.0 M
     glibc-headers                 x86_64                2.17-55.el7                      Packages                                650 k
     kernel-headers                x86_64                3.10.0-123.el7                   Packages                                1.4 M
     libmpc                        x86_64                1.0.1-3.el7                      Packages                                 51 k
     mpfr                          x86_64                3.1.1-4.el7                      Packages                                203 k
    
    Transaction Summary
    ====================================================================================================================================
    Install  1 Package (+6 Dependent packages)
    
    Total size: 46 M
    Total download size: 9.2 M
    Installed size: 59 M
    Downloading packages:
    ------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                36 MB/s | 9.2 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : mpfr-3.1.1-4.el7.x86_64                                                                                          1/7 
      Installing : libmpc-1.0.1-3.el7.x86_64                                                                                        2/7 
      Installing : cpp-4.8.2-16.el7.x86_64                                                                                          3/7 
      Installing : kernel-headers-3.10.0-123.el7.x86_64                                                                             4/7 
      Installing : glibc-headers-2.17-55.el7.x86_64                                                                                 5/7 
      Installing : glibc-devel-2.17-55.el7.x86_64                                                                                   6/7 
      Installing : gcc-4.8.2-16.el7.x86_64                                                                                          7/7 
    Packages/productid                                                                                           | 1.6 kB  00:00:00     
      Verifying  : mpfr-3.1.1-4.el7.x86_64                                                                                          1/7 
      Verifying  : glibc-headers-2.17-55.el7.x86_64                                                                                 2/7 
      Verifying  : glibc-devel-2.17-55.el7.x86_64                                                                                   3/7 
      Verifying  : libmpc-1.0.1-3.el7.x86_64                                                                                        4/7 
      Verifying  : kernel-headers-3.10.0-123.el7.x86_64                                                                             5/7 
      Verifying  : gcc-4.8.2-16.el7.x86_64                                                                                          6/7 
      Verifying  : cpp-4.8.2-16.el7.x86_64                                                                                          7/7 
    
    Installed:
      gcc.x86_64 0:4.8.2-16.el7                                                                                                         
    
    Dependency Installed:
      cpp.x86_64 0:4.8.2-16.el7                      glibc-devel.x86_64 0:2.17-55.el7         glibc-headers.x86_64 0:2.17-55.el7        
      kernel-headers.x86_64 0:3.10.0-123.el7         libmpc.x86_64 0:1.0.1-3.el7              mpfr.x86_64 0:3.1.1-4.el7                 
    
    Complete!
    

     

  6. 大功告成!!




    配置网络源:原文:https://blog.csdn.net/random_w/article/details/84023561 
    作者:random_w 

    【1】根据你系统的版本下载合适的repo文件
    查看版本的方式:cat /etc/system-release

    Red Hat Enterprise Linux Server release 7.3 (Maipo)

    上面是我电脑的查询结果,可以看出我的电脑为7版本

    通过如下命令下载repo文件:

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo


    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    【2】修改repo文件
    通过vim 打开下载的repo文件,你可以发现文件中有两个变量,分别是$releasever和$basearch。

    $releasever的值表示当前系统的发行版本,也就是第一步查到的版本,通过sed命令进行替换:

    sed -i 's/$releasever/7/g' CentOS-Base.repo

    注:根据你的版本将7替换即可。

    $basearch是我们的系统硬件架构(CPU指令集),就是我们常说的i386\i486\i586\i686\...

    通过命令arch可以查看:

    [root@localhost yum.repos.d]# arch
    x86_64

    然后根据查询结果将$basearch进行替换,如下面的命令:

    sed -i 's/$basearch/x86_64/g' CentOS-Base.repo

    注:根据你的查询结果将x86_64替换即可。

    【3】通过yum  makecache把服务器的包信息下载到本地电脑缓存起来,方便查询。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值