Linux软件包管理

linux软件包从内容上可分为二进制包和源码包,不同类的软件包使用的管理工具也各不相同,源码包是没有经过编译的包,需要经过GCC,C++等编译器环境编译才能运行,二进制包无需编译,可以直接安装使用

通常而言,可以通过后缀区分源码包和二进制包,例如:以.tar.gz, .zip, .rar结尾的包称之为源码包,以.rpm结尾的软件包称之为二进制包

对于linux系统而言,提供的工具就叫做rpm,我们可以用rpm工具轻松管理rpm包

rpm参数

-a:查询所有已安装的软件包
-q:询问用户,输出信息
-l:打印软件包的列表
-f:查询包含file的软件包
-i:显示软件包信息,包括名称版本描述
-v:打印输出信息
-U:升级软件包
-h:显示安装进度条
-e:卸载软件包
--force:强制安装或者卸载
--nodeps:忽略依赖包
-l:列出软件包的文件
--provides:列出软件包提供的特性
-R:列出软件包依赖的rpm包

rpm包的安装

rpm -ivh 

[root@bogon lizf]# which wget  
/usr/bin/which:nowgetin(/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
#我们查找wget命令是发现在主机中没有这个命令

[root@bogon ~]# ls
wget-1.14-18.el7_6.1.x86_64.rpm

#找到安装包后上传到主机

[root@bogon ~]# rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:wget-1.14-18.el7_6.1 ################################# [100%]

#用rpm -ivh 安装wget命令的rpm包

强制安装

[root@bogon ~]# rpm -ivh wget-1.19.5-10.el8.x86_64.rpm 
警告:wget-1.19.5-10.el8.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
错误:依赖检测失败:
        libgnutls.so.30()(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libgnutls.so.30(GNUTLS_3_4)(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libgnutls.so.30(GNUTLS_3_6_3)(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libidn2.so.0()(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libidn2.so.0(IDN2_0.0.0)(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libmetalink.so.3()(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libnettle.so.6()(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libnettle.so.6(NETTLE_6)(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
        libpsl.so.5()(64bit) 被 wget-1.19.5-10.el8.x86_64 需要
当我们要安装其他版本的wget安装包时会报需要依赖,如果我们想强制安装时就需要加 --force --nodeps  (不建议这么安装)
[root@bogon ~]# rpm -ivh wget-1.19.5-10.el8.x86_64.rpm --force --nodeps 
警告:wget-1.19.5-10.el8.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:wget-1.19.5-10.el8 ################################# [100%]

rpm包的查看

rpm -qa 软件包名称

[root@bogon ~]# rpm -qa |grep wget
wget-1.14-18.el7_6.1.x86_64

#查看wget安装包版本信息

rpm -qi  软件包名称 :查看软件安装的版本信息

Linux软件包管理
[root@bogon ~]# rpm -qi wget
Name        : wget
Version     : 1.14
Release     : 18.el7_6.1
Architecture: x86_64
Install Date: 2021年08月18日 星期三 23时02分56秒
Group       : Applications/Internet
Size        : 2055573
License     : GPLv3+
Signature   : RSA/SHA256, 2019年05月16日 星期四 23时48分07秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : wget-1.14-18.el7_6.1.src.rpm
Build Date  : 2019年05月16日 星期四 05时02分02秒
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/wget/
Summary     : A utility for retrieving files using the HTTP or FTP protocols
Description :
GNU Wget is a file retrieval utility which can use either the HTTP or
FTP protocols. Wget features include the ability to work in the
background while you are logged out, recursive retrieval of
directories, file name wildcard matching, remote file timestamp
storage and comparison, use of Rest with FTP servers and Range with
HTTP servers to retrieve files over slow or unstable connections,
support for Proxy servers, and configurability.
Name        : wget
Version     : 1.19.5
Release     : 10.el8
Architecture: x86_64
Install Date: 2021年08月18日 星期三 23时32分32秒
Group       : Applications/Internet
Size        : 2895440
License     : GPLv3+
Signature   : RSA/SHA256, 2020年04月29日 星期三 00时08分57秒, Key ID 05b555b38483c65d
Source RPM  : wget-1.19.5-10.el8.src.rpm
Build Date  : 2020年04月27日 星期一 10时09分54秒
Build Host  : x86-02.mbox.centos.org
Relocations : (not relocatable)
Packager    : CentOS Buildsys <bugs@centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/wget/
Summary     : A utility for retrieving files using the HTTP or FTP protocols
Description :
GNU Wget is a file retrieval utility which can use either the HTTP or
FTP protocols. Wget features include the ability to work in the
background while you are logged out, recursive retrieval of
directories, file name wildcard matching, remote file timestamp
storage and comparison, use of Rest with FTP servers and Range with
HTTP servers to retrieve files over slow or unstable connections,
support for Proxy servers, and configurability.
rpm -qi wget 

rpm -ql  软件包名称 :查看软件安装路径

Linux软件包管理
[root@bogon ~]# rpm -ql wget
/etc/wgetrc
/usr/bin/wget
/usr/share/doc/wget-1.14
/usr/share/doc/wget-1.14/AUTHORS
/usr/share/doc/wget-1.14/COPYING
/usr/share/doc/wget-1.14/MAILING-LIST
/usr/share/doc/wget-1.14/NEWS
/usr/share/doc/wget-1.14/README
/usr/share/doc/wget-1.14/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/locale/be/LC_MESSAGES/wget.mo
/usr/share/locale/bg/LC_MESSAGES/wget.mo
/usr/share/locale/ca/LC_MESSAGES/wget.mo
/usr/share/locale/cs/LC_MESSAGES/wget.mo
/usr/share/locale/da/LC_MESSAGES/wget.mo
/usr/share/locale/de/LC_MESSAGES/wget.mo
/usr/share/locale/el/LC_MESSAGES/wget.mo
/usr/share/locale/en_GB/LC_MESSAGES/wget.mo
/usr/share/locale/eo/LC_MESSAGES/wget.mo
/usr/share/locale/es/LC_MESSAGES/wget.mo
/usr/share/locale/et/LC_MESSAGES/wget.mo
/usr/share/locale/eu/LC_MESSAGES/wget.mo
/usr/share/locale/fi/LC_MESSAGES/wget.mo
/usr/share/locale/fr/LC_MESSAGES/wget.mo
/usr/share/locale/ga/LC_MESSAGES/wget.mo
/usr/share/locale/gl/LC_MESSAGES/wget.mo
/usr/share/locale/he/LC_MESSAGES/wget.mo
/usr/share/locale/hr/LC_MESSAGES/wget.mo
/usr/share/locale/hu/LC_MESSAGES/wget.mo
/usr/share/locale/id/LC_MESSAGES/wget.mo
/usr/share/locale/it/LC_MESSAGES/wget.mo
/usr/share/locale/ja/LC_MESSAGES/wget.mo
/usr/share/locale/lt/LC_MESSAGES/wget.mo
/usr/share/locale/nb/LC_MESSAGES/wget.mo
/usr/share/locale/nl/LC_MESSAGES/wget.mo
/usr/share/locale/pl/LC_MESSAGES/wget.mo
/usr/share/locale/pt/LC_MESSAGES/wget.mo
/usr/share/locale/pt_BR/LC_MESSAGES/wget.mo
/usr/share/locale/ro/LC_MESSAGES/wget.mo
/usr/share/locale/ru/LC_MESSAGES/wget.mo
/usr/share/locale/sk/LC_MESSAGES/wget.mo
/usr/share/locale/sl/LC_MESSAGES/wget.mo
/usr/share/locale/sr/LC_MESSAGES/wget.mo
/usr/share/locale/sv/LC_MESSAGES/wget.mo
/usr/share/locale/tr/LC_MESSAGES/wget.mo
/usr/share/locale/uk/LC_MESSAGES/wget.mo
/usr/share/locale/vi/LC_MESSAGES/wget.mo
/usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
/usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
/usr/share/man/man1/wget.1.gz
/etc/wgetrc
/usr/bin/wget
/usr/lib/.build-id
/usr/lib/.build-id/8d
/usr/lib/.build-id/8d/ec58c9a41fa3f0d9966de12c634bfa25b11451
/usr/share/doc/wget
/usr/share/doc/wget/AUTHORS
/usr/share/doc/wget/COPYING
/usr/share/doc/wget/MAILING-LIST
/usr/share/doc/wget/NEWS
/usr/share/doc/wget/README
/usr/share/doc/wget/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/locale/be/LC_MESSAGES/wget.mo
/usr/share/locale/bg/LC_MESSAGES/wget.mo
/usr/share/locale/ca/LC_MESSAGES/wget.mo
/usr/share/locale/cs/LC_MESSAGES/wget.mo
/usr/share/locale/da/LC_MESSAGES/wget.mo
/usr/share/locale/de/LC_MESSAGES/wget.mo
/usr/share/locale/el/LC_MESSAGES/wget.mo
/usr/share/locale/en_GB/LC_MESSAGES/wget.mo
/usr/share/locale/eo/LC_MESSAGES/wget.mo
/usr/share/locale/es/LC_MESSAGES/wget.mo
/usr/share/locale/et/LC_MESSAGES/wget.mo
/usr/share/locale/eu/LC_MESSAGES/wget.mo
/usr/share/locale/fi/LC_MESSAGES/wget.mo
/usr/share/locale/fr/LC_MESSAGES/wget.mo
/usr/share/locale/ga/LC_MESSAGES/wget.mo
/usr/share/locale/gl/LC_MESSAGES/wget.mo
/usr/share/locale/he/LC_MESSAGES/wget.mo
/usr/share/locale/hr/LC_MESSAGES/wget.mo
/usr/share/locale/hu/LC_MESSAGES/wget.mo
/usr/share/locale/id/LC_MESSAGES/wget.mo
/usr/share/locale/it/LC_MESSAGES/wget.mo
/usr/share/locale/ja/LC_MESSAGES/wget.mo
/usr/share/locale/lt/LC_MESSAGES/wget.mo
/usr/share/locale/nb/LC_MESSAGES/wget.mo
/usr/share/locale/nl/LC_MESSAGES/wget.mo
/usr/share/locale/pl/LC_MESSAGES/wget.mo
/usr/share/locale/pt/LC_MESSAGES/wget.mo
/usr/share/locale/pt_BR/LC_MESSAGES/wget.mo
/usr/share/locale/ro/LC_MESSAGES/wget.mo
/usr/share/locale/ru/LC_MESSAGES/wget.mo
/usr/share/locale/sk/LC_MESSAGES/wget.mo
/usr/share/locale/sl/LC_MESSAGES/wget.mo
/usr/share/locale/sr/LC_MESSAGES/wget.mo
/usr/share/locale/sv/LC_MESSAGES/wget.mo
/usr/share/locale/tr/LC_MESSAGES/wget.mo
/usr/share/locale/uk/LC_MESSAGES/wget.mo
/usr/share/locale/vi/LC_MESSAGES/wget.mo
/usr/share/locale/zh_CN/LC_MESSAGES/wget.mo
/usr/share/locale/zh_TW/LC_MESSAGES/wget.mo
/usr/share/man/man1/wget.1.gz
rpm -ql wget

rpm包的升级(以openssh为例)

先查看openssh的安装包版本

[root@bogon ~]# rpm -qa |grep openssh
openssh-server-7.4p1-21.el7.x86_64
openssh-clients-7.4p1-21.el7.x86_64
openssh-7.4p1-21.el7.x86_64

最新安装包版本为openssh-8.6p1-1.el7.x86_64.rpm,使用rpm -Uvh升级

[root@bogon ROOT]# ls
openssh-8.6p1-1.el7.x86_64.rpm          openssh-askpass-gnome-8.6p1-1.el7.x86_64.rpm  openssh-debuginfo-8.6p1-1.el7.x86_64.rpm  openssl-1.0.2k-19.el7.x86_64.rpm        openssl-libs-1.0.2k-19.el7.x86_64.rpm
openssh-askpass-8.6p1-1.el7.x86_64.rpm  openssh-clients-8.6p1-1.el7.x86_64.rpm        openssh-server-8.6p1-1.el7.x86_64.rpm     openssl-devel-1.0.2k-19.el7.x86_64.rpm  readme.txt
[root@bogon ROOT]# rpm -Uvh openssh-8.6p1-1.el7.x86_64.rpm openssh-clients-8.6p1-1.el7.x86_64.rpm  openssh-server-8.6p1-1.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:openssh-8.6p1-1.el7              ################################# [ 17%]
   2:openssh-clients-8.6p1-1.el7      ################################# [ 33%]
   3:openssh-server-8.6p1-1.el7       ################################# [ 50%]
正在清理/删除...
   4:openssh-server-7.4p1-21.el7      ################################# [ 67%]
   5:openssh-clients-7.4p1-21.el7     ################################# [ 83%]
   6:openssh-7.4p1-21.el7             ################################# [100%]

[root@bogon ROOT]# sshd -V        #查看openssh版本信息
unknown option -- V
OpenSSH_8.6p1, OpenSSL 1.0.1e-fips 11 Feb 2013
usage: sshd [-46DdeiqTt] [-C connection_spec] [-c host_cert_file]
[-E log_file] [-f config_file] [-g login_grace_time]
[-h host_key_file] [-o option] [-p port] [-u len]

rpm -qa 查看openssh包信息

[root@bogon ROOT]# rpm -qa | grep openssh
openssh-clients-8.6p1-1.el7.x86_64
openssh-8.6p1-1.el7.x86_64
openssh-server-8.6p1-1.el7.x86_64
#升级成功

rpm包的卸载 

rpm -e 安装包名 

[root@bogon ROOT]# rpm -e lrzsz-0.12.20-43.el8.x86_64
[root@bogon ROOT]# rpm -qa | grep lrzsz              
[root@bogon ROOT]# 

 

Linux软件包管理

上一篇:120名商家眼中微信营销的十个真相


下一篇:[Java- 03] JavaAPI CHM阅读