7 安装软件包的三种方法 rpm包介绍 rpm工具用法 yum工具用法 yum搭建本地仓库...

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1.安装软件包的三种方法。

  • 使用RPM工具安装某一个程序时,有可能因为该程序包依赖另一个程序包而无法安装。
  • 使用yum工具时,就可以连同依赖的程序包一起安装。
  • 源码包安装

2.rpm包介绍。

  • linux系统中存在着一个关于RPM的数据库,它记录了安装的包以及包与包之间的依赖关系。
  • RPM包是预先在linux机器上编译并打包的文件,安装非常快捷。
  • 缺点:安装环境必须与编译时的环境一致或者相当,包与包之间存在着相互依赖的情况,卸载包时需要先把依赖的包卸载。如果依赖的包是系统所必需的,就不能卸载这个包,否则系统会崩溃。
  • 每个RPM包的名称都由-和.分成若干部分。
  • 有些RPM包并没有写具体的平台而是noarch,说明这个RPM包没有硬件平台限制。

加载光驱

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt/
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL
[root@localhost ~]# ls /mnt/Packages/|head
389-ds-base-1.3.7.5-18.el7.x86_64.rpm
389-ds-base-libs-1.3.7.5-18.el7.x86_64.rpm
abattis-cantarell-fonts-0.0.25-1.el7.noarch.rpm
abrt-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-ccpp-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-kerneloops-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-pstoreoops-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-python-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-vmcore-2.1.11-50.el7.centos.x86_64.rpm
abrt-addon-xorg-2.1.11-50.el7.centos.x86_64.rpm

3.rpm工具介绍

安装PRM命令

cd /mnt/Packages/

[root@localhost Packages]# rpm -ivh libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:libjpeg-turbo-devel-1.2.90-5.el7 ################################# [100%]
  • -i:表示安装
  • -v:表示可视化
  • -h:表示显示安装进度
  • --force:表示强制安装,即使覆盖属于其他包的文件也要安装。
  • --nodeps:表示当要安装的RPM包依赖于其他包时,即使其他包没有安装,也要安装这个包。

升级RPM包

rpm -Uvh filename         -U选项表示升级。

卸载RPM包

rpm -qa:先查

rpm -e filename

[root@localhost Packages]# rpm -qa libjpeg-turbo-devel
libjpeg-turbo-devel-1.2.90-5.el7.x86_64
[root@localhost Packages]# rpm -e libjpeg-turbo-devel

 

 

-e 选项后的filename和安装时有区别的。安装时,是把一个存在的文件作为参数,而卸载时需要包名即可。

查询一个包是否已安装

rpm -q RPM 包名   包名是不带平台信息和后缀名的。

[root@localhost Packages]# rpm -ivh libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:libjpeg-turbo-devel-1.2.90-5.el7 ################################# [100%]
[root@localhost Packages]# rpm -q libjpeg-turbo-devel
libjpeg-turbo-devel-1.2.90-5.el7.x86_64

rpm -qa 查询当前系统所有已安装的RPM包。

[root@localhost Packages]# rpm -q libjpeg-turbo-devel
libjpeg-turbo-devel-1.2.90-5.el7.x86_64
[root@localhost Packages]# rpm -qa |head
desktop-file-utils-0.23-1.el7.x86_64
man-db-2.6.3-9.el7.x86_64
ibus-gtk2-1.5.17-2.el7.x86_64
libreport-python-2.1.11-40.el7.centos.x86_64
hyperv-daemons-0-0.32.20161211git.el7.x86_64
tzdata-2018c-1.el7.noarch
libX11-common-1.6.5-1.el7.noarch
kexec-tools-2.0.15-13.el7.x86_64
keybinder3-0.3.0-1.el7.x86_64
libvisual-0.4.0-16.el7.x86_64

得到一个已安装的RPM包的相关信息

rpm -qi 包名,不需要加平台信息和后缀名。

[root@localhost Packages]# rpm -qi libjpeg-turbo-devel
Name        : libjpeg-turbo-devel
Version     : 1.2.90
Release     : 5.el7
Architecture: x86_64
Install Date: 2018年06月26日 星期二 15时04分27秒
Group       : Development/Libraries
Size        : 321621
License     : IJG
Signature   : RSA/SHA256, 2014年07月04日 星期五 10时55分32秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : libjpeg-turbo-1.2.90-5.el7.src.rpm
Build Date  : 2014年06月10日 星期二 11时48分52秒
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem 
Vendor      : CentOS
URL         : http://sourceforge.net/projects/libjpeg-turbo
Summary     : Headers for the libjpeg-turbo library
Description :
This package contains header files necessary for developing programs which
will manipulate JPEG files using the libjpeg-turbo library.

列出一个RPM包的安装文件

rpm -ql 包名

[root@localhost Packages]# rpm -ql libjpeg-turbo-devel
/usr/include/jconfig.h
/usr/include/jerror.h
/usr/include/jmorecfg.h
/usr/include/jpeglib.h
/usr/lib64/libjpeg.so
/usr/share/doc/libjpeg-turbo-devel-1.2.90
/usr/share/doc/libjpeg-turbo-devel-1.2.90/coderules.txt
/usr/share/doc/libjpeg-turbo-devel-1.2.90/example.c
/usr/share/doc/libjpeg-turbo-devel-1.2.90/jconfig.txt
/usr/share/doc/libjpeg-turbo-devel-1.2.90/libjpeg.txt
/usr/share/doc/libjpeg-turbo-devel-1.2.90/structure.txt

列出某个文件属于哪个rpm包

[root@localhost Packages]# rpm -qf /usr/lib64/libjpeg.so
libjpeg-turbo-devel-1.2.90-5.el7.x86_64

4.yum工具的用法

列出所有可用的RPM包

yum list

[root@localhost Packages]# yum list |head -n 20
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
已安装的软件包
GConf2.x86_64                               3.2.6-8.el7                @base    
GeoIP.x86_64                                1.5.0-11.el7               @anaconda
ModemManager.x86_64                         1.6.10-1.el7               @base    
ModemManager-glib.x86_64                    1.6.10-1.el7               @base    
NetworkManager.x86_64                       1:1.10.2-14.el7_5          @updates 
NetworkManager-adsl.x86_64                  1:1.10.2-14.el7_5          @updates 
NetworkManager-bluetooth.x86_64             1:1.10.2-14.el7_5          @updates 
NetworkManager-glib.x86_64                  1:1.10.2-14.el7_5          @updates 
NetworkManager-libnm.x86_64                 1:1.10.2-14.el7_5          @updates 
NetworkManager-libreswan.x86_64             1.2.4-2.el7                @base    
NetworkManager-libreswan-gnome.x86_64       1.2.4-2.el7                @base    
NetworkManager-ppp.x86_64                   1:1.10.2-14.el7_5          @updates 
NetworkManager-team.x86_64                  1:1.10.2-14.el7_5          @updates 
NetworkManager-tui.x86_64                   1:1.10.2-14.el7_5          @updates 

搜索RPM包

yum search vim [相关关键词]

[root@localhost Packages]# yum search vim
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
====================================================================================== N/S matched: vim =======================================================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

用grep来过滤,从而找到相应的RPM包

[root@localhost Packages]# yum list |grep 'vim'
vim-common.x86_64                           2:7.4.160-4.el7            @base    
vim-enhanced.x86_64                         2:7.4.160-4.el7            @base    
vim-filesystem.x86_64                       2:7.4.160-4.el7            @base    
vim-minimal.x86_64                          2:7.4.160-4.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-4.el7            base 

安装RPM包

yum install [-y] [RPM包名],不加-y选项,以用户交互的方式安装。

[root@localhost Packages]# yum install -y protobuf-vim
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                                                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 protobuf-vim.x86_64.0.2.5.0-8.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================================================================================
 Package                                          架构                                       版本                                               源                                        大小
===============================================================================================================================================================================================
正在安装:
 protobuf-vim                                     x86_64                                     2.5.0-8.el7                                        base                                     8.7 k

事务概要
===============================================================================================================================================================================================
安装  1 软件包

总下载量:8.7 k
安装大小:3.7 k
Downloading packages:
protobuf-vim-2.5.0-8.el7.x86_64.rpm                                                                                                                                     | 8.7 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : protobuf-vim-2.5.0-8.el7.x86_64                                                                                                                                            1/1 
  验证中      : protobuf-vim-2.5.0-8.el7.x86_64                                                                                                                                            1/1 

已安装:
  protobuf-vim.x86_64 0:2.5.0-8.el7                                                                                                                                                            

完毕!

卸载RPM包

yum remove [-y] [RPM包名].

[root@localhost Packages]# yum remove protobuf-vim
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 protobuf-vim.x86_64.0.2.5.0-8.el7 将被 删除
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================================================================================
 Package                                          架构                                       版本                                              源                                         大小
===============================================================================================================================================================================================
正在删除:
 protobuf-vim                                     x86_64                                     2.5.0-8.el7                                       @base                                     3.7 k

事务概要
===============================================================================================================================================================================================
移除  1 软件包

安装大小:3.7 k
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : protobuf-vim-2.5.0-8.el7.x86_64                                                                                                                                            1/1 
  验证中      : protobuf-vim-2.5.0-8.el7.x86_64                                                                                                                                            1/1 

删除:
  protobuf-vim.x86_64 0:2.5.0-8.el7                                                                                                                                                            

完毕!

升级RPM包

yum update [-y] [RPM包]。

[root@localhost Packages]# yum update bash
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
No packages marked for update

5.yum搭建本地仓库

挂载光盘

[root@localhost Packages]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /mnt 忙
       /dev/sr0 已经挂载到 /mnt 上

删除/etc/yum.repos.d目录下所有的repo文件(删除之前,最好先做一个备份)。

[root@localhost Packages]# cp -r /etc/yum.repos.d /etc/yum.repos.d_bak
[root@localhost Packages]# rm -rf /etc/yum.repos.d/*

创建新文件dvd.repo。

[root@localhost Packages]# vim /etc/yum.repos.d/dvd.repo

7 安装软件包的三种方法 rpm包介绍 rpm工具用法 yum工具用法 yum搭建本地仓库..._第1张图片

刷新repos生成缓存。安装tftp的RPM包。

[root@localhost Packages]# yum makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
dvd                                                                                                                                                                     | 3.6 kB  00:00:00     
(1/4): dvd/group_gz                                                                                                                                                     | 166 kB  00:00:00     
(2/4): dvd/filelists_db                                                                                                                                                 | 3.1 MB  00:00:00     
(3/4): dvd/primary_db                                                                                                                                                   | 3.1 MB  00:00:00     
(4/4): dvd/other_db                                                                                                                                                     | 1.3 MB  00:00:00     
元数据缓存已建立
[root@localhost Packages]# yum install -y tftp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tftp.x86_64.0.5.2-22.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================================================================================
 Package                                     架构                                          版本                                               源                                          大小
===============================================================================================================================================================================================
正在安装:
 tftp                                        x86_64                                        5.2-22.el7                                         dvd                                         38 k

事务概要
===============================================================================================================================================================================================
安装  1 软件包

总下载量:38 k
安装大小:52 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : tftp-5.2-22.el7.x86_64                                                                                                                                                     1/1 
  验证中      : tftp-5.2-22.el7.x86_64                                                                                                                                                     1/1 

已安装:
  tftp.x86_64 0:5.2-22.el7                                                                                                                                                                     

完毕!

 

转载于:https://my.oschina.net/u/3866192/blog/1835588

你可能感兴趣的:(7 安装软件包的三种方法 rpm包介绍 rpm工具用法 yum工具用法 yum搭建本地仓库...)