linux_yum软件包管理安装

来源:互联网 发布:李兴华 java 框架 编辑:程序博客网 时间:2024/06/03 14:45
### yum安装命令
rpm命令的一个缺点是安装时需要检查依赖关系,如果依赖关系不满足,软件就不会安装成功;若强制安装或者使用—nodeps不检查依赖关系,即使安装成功,在以后使用时也会出现一些问题。为此,Linux提供了yum命令,此命令会自动解决软件依赖性问题。

## 常用命令
yum list {all|installed|avaliable}          列出所有/已安装/可安装的软件包
举例:

yum info package                            显示某一个软件包的信息
yum install package                         安装软件包
yum reinstall package                       重新安装软件包
yum remove|earse package                    卸载软件包

yum clean {all|packages|metadata}           清除所有/软件包/元数据
举例:
yum clean all //清除所有


1) rpm包的更新
#检查可以更新的软件包
yum check-update
#更新所有的软件包
yum update

#更新特定的软件包
yum update kernel

#大规模的升级
yum upgrade

2) rpm包的安装和删除
#rpm包的安装和删除
yum install xxx【服务名】
yum remove xxx【服务名】

3) yum缓存的相关信息
#清楚缓存中rpm包文件
yum clean packages
#清楚缓存中rpm的头文件
yum clean  headers
#清除缓存中旧的头文件
yum clean old headers
#清除缓存中旧的rpm头文件和包文件
yum clean all

4)软件包信息查询
#列出资源库中所有可以安装或更新的rpm包
yum list

#列出资源库中特定的可以安装或更新以及已经安装的rpm包
yum list firfox*
N:可以在rpm包名中使用通配符,查询类似的rpm包

#列出资源库中所有可以更新的rpm包
yum list updates

#列出已经安装的所有的rpm包
yum list installed

#列出已经安装的但是不包含在资源库中的rpm包
yum list extras
N:通过如网站下载安装的rpm包  

#rpm包信息显示(info参数同list),列出资源库中所有可以安装或更新的rpm包的信息
yum info

#列出资源库中特定的可以安装或更新以及已经安装的rpm包的信息

yum info firefox*
N:可以在rpm包名中使用匹配符

#列出资源库中所有可以更新的rpm包的信息
yum info updates

#列出已经安装的所有的rpm包的信息

 yum info installed

#列出已经安装的但是不包含在资源库中的rpm包的信息
yum info extras
N:通过如网站下载安装的rpm包的信息

#搜索匹配特定字符的rpm包
yum search firofox
#搜索包含特定文件的rpm包
yum provides firefox

(三)yum软件源更新
http://mirrors.163.com/.help/centos.html

### yum解释
yum ,全称为:Yellow dog Updater, Modified,是一个基于RPM 包管理的字符前端软件包管理器,它基于C/S架构,能够从配置好的yum仓库自动下载 RPM 包并且安装,可以处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

yum的仓库由各共享的rpm包及由包之间的依赖关系的文件列表等元数据文件组成。 yum的客户端由yum配置文件,缓存元数据组成。 yum客户端的工作原理分析:

1.yum源配置完成后,yum会到各可用的yum仓库下载元数据到本地,并缓存在/var/cache/yum这个目录下。
2.当管理员想要安装某个软件时,yum会根据具体的操作请求分析缓存在系统本地的元数据,结合系统已经安装的软件包,分析出要安装或升级的软件包的列表。
3.向yum仓库请求分析出的软件包列表中的软件,下载到本地客户端完成安装。
4.本次安装完成后,清除本次安装过程中下载到本地的软件包,以节省硬盘空间。

yum主配置文件为/etc/yum.conf:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0        
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=19&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

文件格式解说:
achedir        指的是下载软件包缓存目录
$basearch       对应为程序的版本,对yum而言指的是redhat-release版本,在使用时会替换成系统的主版本号。
$releasever     对应为系统的硬件架构,如i686,x86-64,noarch等
keepcache       软件包安装后是否保留软件包,0为不保留
logfile         为yum的系统日志文件
gpgcheck        为是否校验要安装的软件包,1为校验

yum客户端的配置文件通常位于/etc/yum.repos.d/这个目录下,以repo结尾的文件都是yum源的配置文件,yum源的配置文件可以有多个。
[base]
name=CentOS-$releasever - Base
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

这个是系统自带的yum源文件。yum源的配置通常由五部分组成,其中,
[base]是这个yum源的名字
name=....                相当于是这个yum源的注释信息
baseurl=.....            指定对应yum仓库的访问方式,可以使用以下四种方式:
    ftp                    ftp://server/path/to/repo
    http                http://server/path/to/repo
    nfs                    nfs://server/path/to/repo
    本地光盘yum源        file:///path/to/repo
gpgckeck=1              校验软件包
gpgkey=...              指定公钥的位置

yum的用法:
yum [option] command

yum常用的命令有:
yum repolist {all|enabed|disabled}          列出所有/已启用/已禁用的yum源
yum list {all|installed|avaliable}          列出所有/已安装/可安装的软件包
yum info package                            显示某一个软件包的信息
yum install package                         安装软件包
yum reinstall package                       重新安装软件包
yum remove|earse package                    卸载软件包
yum whatprovides|provides files             查询某个文件是哪个软件包生成的
yum grouplist {all|installed|avaliable}     列出所有/已安装/可安装的软件包组
yum groupinfo                               显示某个软件包组的信息
yum groupinstall                            安装某个软件包组
yum groupremove                             删除某个软件包组
yum history                                 查看yum使用的历史
yum clean {all|packages|metadata}           清除所有/软件包/元数据
yum makecache                               生成yum元数据 
yum --nogpgcheck                            不校验公钥文件
yum -y                                      自动进行操作

例子:
1.安装wget下载工具:
[root@localhost ~]# yum install -y wget
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base:
base                                                                                                                                            | 4.0 kB     00:00 ...
epel                                                                                                                                            | 4.3 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.12-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                              Arch                                   Version                                        Repository                            Size
=======================================================================================================================================================================
Installing:
 wget                                 x86_64                                 1.12-10.el6                                    base                                 484 k

Transaction Summary
=======================================================================================================================================================================
Install       1 Package(s)

Total download size: 484 k

d size: 1.8 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : wget-1.12-10.el6.x86_64                                                                                                                             1/1
  Verifying  : wget-1.12-10.el6.x86_64                                                                                                                             1/1

Installed:
  wget.x86_64 0:1.12-10.el6                                                                                                                                            
Complete!
------------------------------------------------------------------------

2.安装开发工具包组:
[root@localhost ~]# yum grouplist | grep "Development tools"
   Development tools
[root@localhost ~]# yum groupinstall -y "Development tools"
Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
 * base:
Package 1:make-3.81-23.el6.x86_64 already installed and latest version
Package 1:pkgconfig-0.23-9.1.el6.x86_64 already installed and latest version
Package binutils-2.20.51.0.2-5.46.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.63-5.1.el6 will be installed
--> Processing Dependency: perl >= 5.005_03 for package: autoconf-2.63-5.1.el6.noarch
--> Processing Dependency: perl >= 5.005 for package: autoconf-2.63-5.1.el6.noarch
...         中间省略
Verifying  : elfutils-0.164-2.el6.x86_64                               106/113
  Verifying  : 1:perl-Module-Pluggable-3.90-144.el6.x86_64               107/113
  Verifying  : byacc-1.9.20070509-7.el6.x86_64                           108/113
  Verifying  : libXft-2.3.2-1.el6.x86_64                                 109/113
  Verifying  : libedit-2.11-4.20080712cvs.1.el6.x86_64                   110/113
  Verifying  : libICE-1.0.6-1.el6.x86_64                                 111/113
  Verifying  : perl-XML-Parser-2.36-7.el6.x86_64                         112/113
  Verifying  : libxcb-1.12-4.el6.x86_64                                  113/113
...         中间省略
Installed:
  autoconf.noarch 0:2.63-5.1.el6                                                 
...         中间省略
  perl-libwww-perl.noarch 0:5.833-5.el6                                          
  perl-version.x86_64 3:0.77-144.el6                                             
  pixman.x86_64 0:0.32.8-1.el6                                                   
  ppl.x86_64 0:0.10.2-11.el6                                                     
  rsync.x86_64 0:3.0.6-12.el6                                                   
  systemtap-client.x86_64 0:2.9-7.el6                                            
  systemtap-devel.x86_64 0:2.9-7.el6                                             
  systemtap-runtime.x86_64 0:2.9-7.el6                                           
  unzip.x86_64 0:6.0-5.el6                                                       
  xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6                                   
  xz-lzma-compat.x86_64 0:4.999.9-0.5.beta.20091007git.el6                       
  zip.x86_64 0:3.0-1.el6_7.1                                                     

Complete!
--------------------------------------------------------

3.查看内核文件的信息
[root@localhost Packages]# yum info kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
Installed Packages
Name        : kernel
Arch        : x86_64
Version     : 2.6.32
Release     : 573.el6
Size        : 126 M
Repo        : installed
From repo   : anaconda-CentOS-201508042137.x86_64
Summary     : The Linux kernel
URL         : http://www.kernel.org/
License     : GPLv2
Description : The kernel package contains the Linux kernel (vmlinuz), the core of any
            : Linux operating system.  The kernel handles the basic functions
            : of the operating system: memory allocation, process allocation, device
            : input and output, etc.

Available Packages
Name        : kernel
Arch        : x86_64
Version     : 2.6.32
Release     : 696.el6
Size        : 32 M
Repo        : base
Summary     : The Linux kernel
URL         : http://www.kernel.org/
License     : GPLv2
Description : The kernel package contains the Linux kernel (vmlinuz), the core of any
            : Linux operating system.  The kernel handles the basic functions
            : of the operating system: memory allocation, process allocation, device
            : input and output, etc.
            
--------------------------------------------------------------------------------

4.在CentOS7上创建本地光盘yum源
#查看系统版本
[root@localhost home]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
#创建光盘挂载点
[root@localhost home]# mkdir /mnt/cdrom
#挂载系统光盘到/mnt/cdrom目录下
[root@localhost home]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
#列出/mnt/cdrom目录的内容
[root@localhost home]# ls /mnt/cdrom
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
#进入/etc/yum.repos.d目录
[root@localhost home]# cd /etc/yum.repos.d/
#创建repo的备份目录
[root@localhost yum.repos.d]# mkdir repo.bak
#把系统原有的repo文件移动到刚创建的备份目录下
[root@localhost yum.repos.d]# mv ./*.repo repo.bak/
#编辑光盘yum的repo文件,加入以下内容,保存退出
[root@localhost yum.repos.d]# vi CentOS-Media.repo

[CentOS-Media]
name=CentOS-Media
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=0

#清除系统上yum源的元数据
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: CentOS-Media
Cleaning up everything
Cleaning up list of fastest mirrors
#生成新的yum元数据
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
CentOS-Media                                                                                                                                    | 3.6 kB  00:00:00     
(1/4): CentOS-Media/group_gz                                                                                                                    | 155 kB  00:00:00     
(2/4): CentOS-Media/filelists_db                                                                                                                | 3.0 MB  00:00:02     
(3/4): CentOS-Media/primary_db                                                                                                                  | 3.0 MB  00:00:01     
(4/4): CentOS-Media/other_db                                                                                                                    | 1.3 MB  00:00:00     
Determining fastest mirrors
Metadata Cache Created
#安装软件进行测试
[root@localhost yum.repos.d]# yum install -y httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos for package: httpd-2.4.6-45.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                Arch                              Version                                        Repository                               Size
=======================================================================================================================================================================
Installing:
 httpd                                  x86_64                            2.4.6-45.el7.centos                            CentOS-Media                            2.7 M
Installing for dependencies:
 httpd-tools                            x86_64                            2.4.6-45.el7.centos                            CentOS-Media                             84 k
 mailcap                                noarch                            2.1.41-2.el7                                   CentOS-Media                             31 k

Transaction Summary
=======================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 2.8 M
Installed size: 9.6 M
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   10 MB/s | 2.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mailcap-2.1.41-2.el7.noarch                                                                                                                         1/3
  Installing : httpd-tools-2.4.6-45.el7.centos.x86_64                                                                                                              2/3
  Installing : httpd-2.4.6-45.el7.centos.x86_64                                                                                                                    3/3
  Verifying  : httpd-tools-2.4.6-45.el7.centos.x86_64                                                                                                              1/3
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                                                                         2/3
  Verifying  : httpd-2.4.6-45.el7.centos.x86_64                                                                                                                    3/3

Installed:
  httpd.x86_64 0:2.4.6-45.el7.centos                                                                                                                                   

Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-45.el7.centos                                                mailcap.noarch 0:2.1.41-2.el7                                               

Complete!
原创粉丝点击