Linux软件包管理之2——yum在线命令

Linux软件包管理

  1. rpm命令管理 https://blog.csdn.net/jiduochou963/article/details/86619233
  2. yum在线命令 https://blog.csdn.net/jiduochou963/article/details/86653645
  3. 源码包管理 https://blog.csdn.net/jiduochou963/article/details/86653703
  4. 脚本安装包 https://blog.csdn.net/jiduochou963/article/details/86655625

二、 yum在线命令

RPM缺点:

  • 安装过程中,rpm包依赖性太强
  • 如果所有rpm包都是手工安装,则rpm包使用难度较大,一些情况下甚至比源码包还要复杂。

注意:yum不支持查询,查询方法仍然依赖RPM包查询命令

yum在线安装

  • 好处:将所有软件包放到官方服务器上,当进行yum在线安装时,可以自动解决依赖性问题。
  • Redhat的yum在线安装需要付费。

yum源文件

  • vim /etc/yum.repos.d/CentOS-Base.repo
[root@localhost Packages]# ls -al /etc/yum.repos.d/
总用量 44
drwxr-xr-x.   2 root root  187 4月  13 2018 .
drwxr-xr-x. 141 root root 8192 1月  24 09:45 ..
# 基本yum源文件,默认生效,另外几个是默认不生效的
-rw-r--r--.   1 root root 1664 4月  29 2018 CentOS-Base.repo
-rw-r--r--.   1 root root 1309 4月  29 2018 CentOS-CR.repo
-rw-r--r--.   1 root root  649 4月  29 2018 CentOS-Debuginfo.repo
-rw-r--r--.   1 root root  314 4月  29 2018 CentOS-fasttrack.repo
-rw-r--r--.   1 root root  630 4月  29 2018 CentOS-Media.repo
-rw-r--r--.   1 root root 1331 4月  29 2018 CentOS-Sources.repo
-rw-r--r--.   1 root root 4768 4月  29 2018 CentOS-Vault.repo
[root@localhost Packages]# 
[root@localhost Packages]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# cat CentOS-Base.repo # 下面的内容  #...表示是我添加的注释,以区别原来的。
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@localhost yum.repos.d]# 

CentOS-Base.repo文件内容中,以下面这几行为例介绍:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

  • [base] 容器的名称,一定要放在[]中;简单来说就是yum源的名字,名称可以自己指定。
  • name 容器说明,可以自己随便写;相当于一个注释
  • mirrorlist 镜像站点,这个可以注释掉
  • baseurl 我们的yum源服务器的地址。默认是CentOS官方的yum源服务器,是可以使用的。国内如果网速慢可以自行改为国内的镜像。
  • enabled 此容器是否生效,默认生效(为1)。即如果不写或写成enabled=1都是生效,写成enabled=0就是不生效
  • gpgcheck 数字证书验证,如果是1是指RPM的数字证书生效,如果是0则不生效。一般开启,保护系统安全。
  • gpgkey 数字证书的公钥文件保存位置,不用修改

  • gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    • //是协议后面跟的双反斜杠,file://文件协议
    • /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7是协议及绝对路径
  • 本机的数字证书如下:
[root@localhost yum.repos.d]# ls -al /etc/pki//rpm-gpg/ 
总用量 12
drwxr-xr-x.  2 root root  104 1月  23 17:34 .
drwxr-xr-x. 11 root root  131 1月  23 17:38 ..
-rw-r--r--.  1 root root 1690 4月  29 2018 RPM-GPG-KEY-CentOS-7
-rw-r--r--.  1 root root 1004 4月  29 2018 RPM-GPG-KEY-CentOS-Debug-7
-rw-r--r--.  1 root root 1690 4月  29 2018 RPM-GPG-KEY-CentOS-Testing-7
[root@localhost yum.repos.d]# 

光盘(系统镜像)搭载本地yum源

如果没有网络,如何使用yum源?

1. 挂载光盘

挂载步骤和前面一样:

#...建立挂载点
[root@localhost cdrom]# mkdir /mnt/cdrom
#...挂载光盘
[root@localhost cdrom]# mount /dev/sr0 /mnt/cdrom/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost cdrom]#
2. 使网络yum源失效

方法一:

  • vim /etc/yum.repos.d/CentOS-Base.repo编辑enable=0使容器(yum源)不生效,但是每一个yum源都要编辑(修改或者添加enable语句),比较麻烦。

方法二:

  • 进入yum源目录
    • cd /etc/yum.repos.d/
  • 修改yum源文件后缀名,使其失效——达到删除的效果,使网络yum源失效
    • mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls -al 
总用量 44
drwxr-xr-x.   2 root root  187 4月  13 2018 .
drwxr-xr-x. 141 root root 8192 1月  24 09:45 ..
-rw-r--r--.   1 root root 1664 4月  29 2018 CentOS-Base.repo
-rw-r--r--.   1 root root 1309 4月  29 2018 CentOS-CR.repo
-rw-r--r--.   1 root root  649 4月  29 2018 CentOS-Debuginfo.repo
-rw-r--r--.   1 root root  314 4月  29 2018 CentOS-fasttrack.repo
-rw-r--r--.   1 root root  630 4月  29 2018 CentOS-Media.repo
-rw-r--r--.   1 root root 1331 4月  29 2018 CentOS-Sources.repo
-rw-r--r--.   1 root root 4768 4月  29 2018 CentOS-Vault.repo
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# ls -al
总用量 44
drwxr-xr-x.   2 root root  191 1月  24 22:10 .
drwxr-xr-x. 141 root root 8192 1月  24 09:45 ..
-rw-r--r--.   1 root root 1664 4月  29 2018 CentOS-Base.repo.bak
-rw-r--r--.   1 root root 1309 4月  29 2018 CentOS-CR.repo
-rw-r--r--.   1 root root  649 4月  29 2018 CentOS-Debuginfo.repo
-rw-r--r--.   1 root root  314 4月  29 2018 CentOS-fasttrack.repo
-rw-r--r--.   1 root root  630 4月  29 2018 CentOS-Media.repo
-rw-r--r--.   1 root root 1331 4月  29 2018 CentOS-Sources.repo
-rw-r--r--.   1 root root 4768 4月  29 2018 CentOS-Vault.repo
[root@localhost yum.repos.d]# 
让光盘yum源生效
  • vim CentOS-Media.repo
[root@localhost yum.repos.d]# cat CentOS-Media.repo  # ...下面的  #...是我自己添加的
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/  #...将地址改为自己的光盘挂载地址,把下面两个不存在的地址注释(注释一定在行首),不然可能会报错。
        file:///media/cdrom/  
        file:///media/cdrecorder/
gpgcheck=1
enabled=0  #...这里改为enabled=1,让yum源配置文件生效
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@localhost yum.repos.d]# vim CentOS-Media.repo
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
:wq
[root@localhost yum.repos.d]# cat CentOS-Media.repo 
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@localhost yum.repos.d]# 

验证:yum list——查看yum源里有哪些软件包可以安装(下面会详细介绍)

[root@localhost yum.repos.d]# yum list
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
...

...
zziplib.i686                                                                          0.13.62-5.el7                                                      c7-media 
zziplib.x86_64                                                                        0.13.62-5.el7                                                      c7-media 
zziplib-devel.i686                                                                    0.13.62-5.el7                                                      c7-media 
zziplib-devel.x86_64                                                                  0.13.62-5.el7                                                      c7-media 
zziplib-utils.x86_64                                                                  0.13.62-5.el7                                                      c7-media 
[root@localhost yum.repos.d]# 

按列从左到右依次是:[包的名称]–[版本]–[yum源的名字]

yum命令

常用yum命令

1. 查询

yum list 查询所有可用软件包列表

[root@localhost ~]# yum list
...

yum search 关键字 搜索服务器上所有和关键字相关的包

[root@localhost ~]# yum search httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
======================================================================= N/S matched: httpd =======================================================================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# 
2. 安装
  • yum -y install 包名
  • 选项:
    • install 安装
    • -y 自动回答yes
      注意:yum中只写包名即可。

如1:mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm

[root@localhost ~]# yum search mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
======================================================================= N/S matched: mysql =======================================================================
MySQL-python.x86_64 : An interface to MySQL
akonadi-mysql.x86_64 : Akonadi MySQL backend support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
dovecot-mysql.x86_64 : MySQL back end for dovecot
freeradius-mysql.x86_64 : MySQL support for freeradius
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
mysql-connector-java.noarch : Official JDBC driver for MySQL
mysql-connector-odbc.x86_64 : ODBC driver for MySQL
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
qt-mysql.i686 : MySQL driver for Qt's SQL classes
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
qt5-qtbase-mysql.i686 : MySQL driver for Qt5's SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5's SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
rsyslog-mysql.x86_64 : MySQL support for rsyslog
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients

  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# yum -y install mysql-connector-odbc.x86_64 ^C
[root@localhost ~]# rpm -ivh mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm
错误:打开 mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm 失败: 没有那个文件或目录
[root@localhost ~]# rpm -ivh /mnt/cdrom/Packages/mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm 
警告:/mnt/cdrom/Packages/mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
错误:依赖检测失败:
        libodbc.so.2()(64bit) 被 mysql-connector-odbc-5.2.5-7.el7.x86_64 需要
        libodbcinst.so.2()(64bit) 被 mysql-connector-odbc-5.2.5-7.el7.x86_64 需要
[root@localhost ~]# yum -y install mysql-connector-odbc.x86_64 
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
c7-media                                                                                                                                   | 3.6 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-connector-odbc.x86_64.0.5.2.5-7.el7 将被 安装
--> 正在处理依赖关系 libodbcinst.so.2()(64bit),它被软件包 mysql-connector-odbc-5.2.5-7.el7.x86_64 需要
--> 正在处理依赖关系 libodbc.so.2()(64bit),它被软件包 mysql-connector-odbc-5.2.5-7.el7.x86_64 需要
--> 正在检查事务
---> 软件包 unixODBC.x86_64.0.2.3.1-11.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==================================================================================================================================================================
 Package                                        架构                             版本                                    源                                  大小
==================================================================================================================================================================
正在安装:
 mysql-connector-odbc                           x86_64                           5.2.5-7.el7                             c7-media                           142 k
为依赖而安装:
 unixODBC                                       x86_64                           2.3.1-11.el7                            c7-media                           413 k

事务概要
==================================================================================================================================================================
安装  1 软件包 (+1 依赖软件包)

总下载量:555 k
安装大小:1.6 M
Downloading packages:
警告:/mnt/cdrom/Packages/mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
mysql-connector-odbc-5.2.5-7.el7.x86_64.rpm 的公钥尚未安装
------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                               11 MB/s | 555 kB  00:00:00     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) "
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-5.1804.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : unixODBC-2.3.1-11.el7.x86_64                                                                                                                  1/2 
  正在安装    : mysql-connector-odbc-5.2.5-7.el7.x86_64                                                                                                       2/2 
  验证中      : mysql-connector-odbc-5.2.5-7.el7.x86_64                                                                                                       1/2 
  验证中      : unixODBC-2.3.1-11.el7.x86_64                                                                                                                  2/2 

已安装:
  mysql-connector-odbc.x86_64 0:5.2.5-7.el7                                                                                                                       

作为依赖被安装:
  unixODBC.x86_64 0:2.3.1-11.el7                                                                                                                                  

完毕!
[root@localhost ~]# 

如2:yum -y install gcc——C语言编译器

[root@localhost ~]# yum search gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
======================================================================== N/S matched: gcc ========================================================================
gcc-c++.x86_64 : C++ support for GCC
gcc-gnat.x86_64 : Ada 95 support for GCC
gcc-objc.x86_64 : Objective-C support for GCC
gcc-objc++.x86_64 : Objective-C++ support for GCC
gcc-plugin-devel.x86_64 : Support for compiling GCC plugins
libgcc.i686 : GCC version 4.8 shared support library
libgcc.x86_64 : GCC version 4.8 shared support library
relaxngcc-javadoc.noarch : Javadoc for relaxngcc
compat-gcc-44.x86_64 : Compatibility GNU Compiler Collection
compat-gcc-44-c++.x86_64 : C++ support for compatibility compiler
compat-gcc-44-gfortran.x86_64 : Fortran support for compatibility compiler
gcc.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
gcc-gfortran.x86_64 : Fortran support
gcc-go.x86_64 : Go support
libgomp.i686 : GCC OpenMP v3.0 shared support library
libgomp.x86_64 : GCC OpenMP v3.0 shared support library
libmudflap.i686 : GCC mudflap shared support library
libmudflap.x86_64 : GCC mudflap shared support library
libmudflap-devel.i686 : GCC mudflap support
libmudflap-devel.x86_64 : GCC mudflap support
libquadmath.i686 : GCC __float128 shared support library
libquadmath.x86_64 : GCC __float128 shared support library
libquadmath-devel.i686 : GCC __float128 support
libquadmath-devel.x86_64 : GCC __float128 support
relaxngcc.noarch : RELAX NG Compiler Compiler

  名称和简介匹配 only,使用“search all”试试。
[root@localhost ~]# gcc
bash: gcc: 未找到命令...
[root@localhost ~]# rpm -ivh /mnt/cdrom/Packages/gcc-c++-4.8.5-28.el7.x86_64.rpm 
错误:依赖检测失败:
        gcc = 4.8.5-28.el7 被 gcc-c++-4.8.5-28.el7.x86_64 需要
        libmpc.so.3()(64bit) 被 gcc-c++-4.8.5-28.el7.x86_64 需要
        libstdc++-devel = 4.8.5-28.el7 被 gcc-c++-4.8.5-28.el7.x86_64 需要
[root@localhost ~]# yum -y install gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-28.el7 将被 安装
--> 正在处理依赖关系 cpp = 4.8.5-28.el7,它被软件包 gcc-4.8.5-28.el7.x86_64 需要
--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-28.el7.x86_64 需要
--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-4.8.5-28.el7.x86_64 需要
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-28.el7 将被 安装
---> 软件包 glibc-devel.x86_64.0.2.17-222.el7 将被 安装
--> 正在处理依赖关系 glibc-headers = 2.17-222.el7,它被软件包 glibc-devel-2.17-222.el7.x86_64 需要
--> 正在处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.17-222.el7.x86_64 需要
---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装
--> 正在检查事务
---> 软件包 glibc-headers.x86_64.0.2.17-222.el7 将被 安装
--> 正在处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.17-222.el7.x86_64 需要
--> 正在处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.17-222.el7.x86_64 需要
--> 正在检查事务
---> 软件包 kernel-headers.x86_64.0.3.10.0-862.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==================================================================================================================================================================
 Package                                   架构                              版本                                       源                                   大小
==================================================================================================================================================================
正在安装:
 gcc                                       x86_64                            4.8.5-28.el7                               c7-media                             16 M
为依赖而安装:
 cpp                                       x86_64                            4.8.5-28.el7                               c7-media                            5.9 M
 glibc-devel                               x86_64                            2.17-222.el7                               c7-media                            1.1 M
 glibc-headers                             x86_64                            2.17-222.el7                               c7-media                            678 k
 kernel-headers                            x86_64                            3.10.0-862.el7                             c7-media                            7.1 M
 libmpc                                    x86_64                            1.0.1-3.el7                                c7-media                             51 k

事务概要
==================================================================================================================================================================
安装  1 软件包 (+5 依赖软件包)

总下载量:31 M
安装大小:59 M
Downloading packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                               41 MB/s |  31 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : libmpc-1.0.1-3.el7.x86_64                                                                                                                     1/6 
  正在安装    : cpp-4.8.5-28.el7.x86_64                                                                                                                       2/6 
  正在安装    : kernel-headers-3.10.0-862.el7.x86_64                                                                                                          3/6 
  正在安装    : glibc-headers-2.17-222.el7.x86_64                                                                                                             4/6 
  正在安装    : glibc-devel-2.17-222.el7.x86_64                                                                                                               5/6 
  正在安装    : gcc-4.8.5-28.el7.x86_64                                                                                                                       6/6 
  验证中      : gcc-4.8.5-28.el7.x86_64                                                                                                                       1/6 
  验证中      : cpp-4.8.5-28.el7.x86_64                                                                                                                       2/6 
  验证中      : glibc-devel-2.17-222.el7.x86_64                                                                                                               3/6 
  验证中      : kernel-headers-3.10.0-862.el7.x86_64                                                                                                          4/6 
  验证中      : glibc-headers-2.17-222.el7.x86_64                                                                                                             5/6 
  验证中      : libmpc-1.0.1-3.el7.x86_64                                                                                                                     6/6 

已安装:
  gcc.x86_64 0:4.8.5-28.el7                                                                                                                                       

作为依赖被安装:
  cpp.x86_64 0:4.8.5-28.el7         glibc-devel.x86_64 0:2.17-222.el7       glibc-headers.x86_64 0:2.17-222.el7       kernel-headers.x86_64 0:3.10.0-862.el7      
  libmpc.x86_64 0:1.0.1-3.el7      

完毕!
[root@localhost ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[root@localhost ~]# yum -y gcc
已加载插件:fastestmirror, langpacks
没有该命令:gcc。请使用 /usr/bin/yum --help
[root@localhost ~]# yum -y install gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 gcc-4.8.5-28.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost ~]# 
升级
  • yum -y update 包名
  • 选项:
    • update 升级
    • -y 自动回答yes
[root@localhost ~]# yum -y update httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No packages marked for update
[root@localhost ~]# 

注:除非爆发致命漏洞,否则应该考虑稳定性,不升级尽量不要升级。
yum -y update是升级Linux中所有的软件包,包括Linux内核。新的内核启用需要人为配置才能启动,直接升级可能会造成系统崩溃。

卸载
  • yum -y remove 包名
  • 选项:
    • remove 卸载
    • -y 自动回答yes

原则:服务器使用最小化安装,用什么软件安装什么,尽量不卸载。
安装有依赖性,卸载同样有依赖性。万一卸载了所依赖的系统包,导致系统崩溃。

yum软件组管理命令

  • yum grouplist
    • 列出所有可用的软件组列表
  • yum groupinstall 软件组名
    • 安装指定软件组,组名可以由grouplist查询出来
    • 注意: 软件组名必须是英文
  • yum groupremove 软件组名
    • 卸载指定软件组
[root@localhost ~]# yum grouplist
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成
[root@localhost ~]# 

软件包名必须是英文;尽管Linux是用中文安装,但Linux本机是不支持中文的(如果是在Linux本机上操作就是纯英文。终端工具中显示的是安装时的语言,所以看到的是中文。)
在终端工具中将语系临时从中文改为英文即可:

[root@localhost ~]# LANG=en_US
[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[root@localhost ~]# 

安装指定软件组

[root@localhost ~]# yum groupinstall "Server with GUI"
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Warning: Group core does not have any packages to install.
Warning: Group gnome-desktop does not have any packages to install.
Warning: Group guest-agents does not have any packages to install.
Package gtk2-immodule-xim-2.24.31-1.el7.x86_64 already installed and latest version
Package imsettings-gsettings-1.6.3-9.el7.x86_64 already installed and latest version
Package ibus-gtk3-1.5.17-2.el7.x86_64 already installed and latest version
Package ibus-gtk2-1.5.17-2.el7.x86_64 already installed and latest version
Package gtk3-immodule-xim-3.22.26-3.el7.x86_64 already installed and latest version
Warning: Group input-methods does not have any packages to install.
Group input-methods does have 2 conditional packages, which may get installed.
Warning: Group guest-desktop-agents does not have any packages to install.
Warning: Group fonts does not have any packages to install.
Warning: Group print-client does not have any packages to install.
Warning: Group desktop-debugging does not have any packages to install.
Warning: Group dial-up does not have any packages to install.
Warning: Group hardware-monitoring does not have any packages to install.
Warning: Group base does not have any packages to install.
Group base does have 1 conditional packages, which may get installed.
Package gstreamer1-plugins-bad-free-1.10.4-3.el7.x86_64 already installed and latest version
Package gstreamer1-plugins-good-1.10.4-2.el7.x86_64 already installed and latest version
Package gstreamer1-plugins-ugly-free-1.10.4-3.el7.x86_64 already installed and latest version
Warning: Group multimedia does not have any packages to install.
Warning: Group internet-browser does not have any packages to install.
Warning: Group x11 does not have any packages to install.
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or update
[root@localhost ~]# 

因为已经安装过GUI,haha。
改回来:LANG=zh_CN.utf8


  1. 源码包管理 https://blog.csdn.net/jiduochou963/article/details/86653703

你可能感兴趣的:(#,Linux)