RPM-YUM-包管理工具

概览

Linux操作系统下,安装软件有多种方式:

  • 二进制直接安装 (最简单的就是单文件二进制直接使用)
  • RPM包安装方式,就像windows下面有 .exe 格式的安装包一样,Linux RedHat 系列,有 .rpm 格式的安装包
  • yum安装,yum可以认为安装方式比rpm高级,是基于rpm的,管理rpm包的工具,可以联网自动安装所需要的依赖
  • 编译安装,下载源码编译安装,较为麻烦,比较少用,但有时官网就给这么一种安装方式,也只能用这种,比如redis官网
  • docker安装,直接以docker容器化的方式启动服务

rpm命令的全称是Red Hat Package Manager(Red Hat包管理器),rpm命令包含了五种基本功能(不包括创建rpm包):安装、卸载、升级、查询和验证。

rpm

简单帮助

http://www.rpm.org
rpm --help
man rpm

One of the following basic modes must be selected: Query, Verify, Install/Upgrade/Freshen/Reinstall, Uninstall, Set Owners/Groups, Show Querytags, and Show Configuration.

rpm {-q|--query} [select-options] [query-options]
rpm {-V|--verify} [select-options] [verify-options]
rpm {-i|--install} [install-options] PACKAGE_FILE ...

rpm包在系统光盘的Packages目录当中 /mnt/cdrom/Packages

################################################ rpm的命名规则 ########################################################################

httpd-2.2.15-59.el6.centos.x86_64.rpm

- httpd 软件包名称  
- 2.2.15 软件版本  
- 59 软件发布的次数
- .e16.centos 适合的linux平台,e16是redhat企业版平台
- x86_64 适合的硬件平台
- .rpm 包扩展名

使用场景参考

https://developer.aliyun.com/packageSearch?word=tree

https://mirrors.aliyun.com/centos/7.7.1908/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm?spm=a2c6h.13651111.0.0.54bb2f70OcX1DI&file=tree-1.6.0-10.el7.x86_64.rpm

[root@astest ~]# rpm -ql varnish
/etc/ld.so.conf.d/varnish-x86_64.conf
/etc/logrotate.d/varnish
/etc/varnish
/etc/varnish/default.vcl
...

查看rpm包信息
rpm --query --package tree-1.6.0-10.el7.x86_64.rpm --info
rpm -qpi tree-1.6.0-10.el7.x86_64.rpm

查看rpm包内容
rpm --query --package tree-1.6.0-10.el7.x86_64.rpm --list
rpm -qpl tree-1.6.0-10.el7.x86_64.rpm

查看rpm包的依赖
rpm --query --package tree-1.6.0-10.el7.x86_64.rpm --requires
rpm -qpR tree-1.6.0-10.el7.x86_64.rpm

查看系统里所有安装包
rpm --query --all
rpm -qa 

查看系统里某个软件包所包含的文件是否被动过
rpm -V nginx

查看某个包是否已安装
rpm -qa | grep pkgname

查询某个命令是哪个包安装的
rpm --query --file $(which ifconfig)
rpm -qf $(which ifconfig)

安装rpm包
rpm --install -v --hash tree-1.6.0-10.el7.x86_64.rpm
rpm --install -vv --hash tree-1.6.0-10.el7.x86_64.rpm
rpm -ivh tree-1.6.0-10.el7.x86_64.rpm
rpm --install tree-1.6.0-10.el7.x86_64.rpm
rpm -i tree-1.6.0-10.el7.x86_64.rpm

YUM

简单帮助

http://yum.baseurl.org/wiki/Guides.htl
yum [options] [command] [package ...]

       command is one of:
        * install package1 [package2] [...]
        * update [package1] [package2] [...]
        * update-to [package1] [package2] [...]
        * remove | erase package1 [package2] [...]
        * list [...]
        * info [...]
        * provides | whatprovides feature1 [feature2] [...]
        * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
        * makecache [fast]
        * search string1 [string2] [...]
        * reinstall package1 [package2] [...]
        * deplist package1 [package2] [...]
        * repolist [all|enabled|disabled]
        * repoinfo [all|enabled|disabled]
        * help [command]

Unless the --help or -h option is given, one of the above commands must be present.

/etc/yum.repos.d/    在下面添加repo文件,以增加yum仓库的包数量
/etc/yum.conf

-q, --quiet           quiet operation
-v, --verbose         verbose operation
-y, --assumeyes       answer yes for all questions
--showduplicates      show duplicates, in repos, in list/search commands

使用场景参考

yum install httpd
yum install httpd -y
yum install local.rpm  也可以直接安装本地rpm包

yum update          更新系统里所有的软件包
yum list httpd      列出httpd软件包
yum search httpd    搜索包含httpd字符串的软件包
yum info httpd      显示该软件包信息(在线安装之前需要查看下,可以使用这个命令)
yum list installed  列出所有已安装的软件包 (这个命令可以用来查看某个包是通过哪个仓库安装的)
yum provides $(which ifconfig)  查找某个特定的文件属于哪个包
yum repolist        列出所有软件源
yum clean all       清理所有yum缓存内容

yum deplist         查看软件包的依赖
yum remove httpd
yum update httpd

实践安装nginx

http://nginx.org/en/linux_packages.html#RHEL-CentOS

cat << 'EOF' > /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF

查看能够安装的nginx版本 yum list nginx --showduplicates

yum install nginx-1.16.1

常用 repo 源

https://mirror.tuna.tsinghua.edu.cn/help/centos/
https://developer.aliyun.com/mirror/

yum install epel-release -y

/etc/yum.repos.d/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

/etc/yum.repos.d/CentOS-Base.repo 阿里源

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

/etc/yum.repos.d/base.repo 阿里源 精简版

cat << 'EOF' > /etc/yum.repos.d/base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=0
EOF

/etc/yum.repos.d/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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

/etc/yum.repos.d/epel.repo 清华源

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

/etc/yum.repos.d/epel.repo 阿里源

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
 
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

/etc/yum.repos.d/epel.repo 阿里源 精简版

cat << 'EOF' > /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
enabled=1
gpgcheck=0
EOF

内网 nexus

cat << 'EOF' > /etc/yum.repos.d/base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
baseurl=http://192.168.1.112:8081/repository/aliyun-base/$releasever/os/$basearch/
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
#baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
baseurl=http://192.168.1.112:8081/repository/aliyun-base/$releasever/updates/$basearch/
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
baseurl=http://192.168.1.112:8081/repository/aliyun-base/$releasever/extras/$basearch/
gpgcheck=0
EOF


cat << 'EOF' > /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://mirrors.aliyun.com/epel/7/$basearch
baseurl=http://192.168.1.112:8081/repository/aliyun-epel/7/$basearch
enabled=1
gpgcheck=0
EOF

阿里源 精简版

cat << 'EOF' > /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
enabled=1
gpgcheck=0
EOF

cat << 'EOF' > /etc/yum.repos.d/base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=0
EOF

rpm 搜索网站

rpmfind.net
http://rpmfind.net/linux/centos/6.10/os/x86_64/Packages/tree-1.5.3-3.el6.x86_64.rpm

https://developer.aliyun.com/packageSearch?word=tree
https://mirrors.aliyun.com/centos/6.10/os/x86_64/Packages/tree-1.5.3-3.el6.x86_64.rpm?spm=a2c6h.13651111.0.0.54bb2f70zkm8QB&file=tree-1.5.3-3.el6.x86_64.rpm