RPM 软件包管理机制最早由 Red Hat 公司提出,后来随着版本的升级逐渐融入更多的优秀 特 性 , 成 为 众 多 Linux 发 行 版 中 公 认 的 软 件 包 管 理 标 准 。 在 其 官 方 站 点http://www.rpm.org 中,可以了解到关于 RPM 包管理机制的详细资料。
#查看RPM手册页
[root@CentOS7-4 ~]# man rpm
-qa:显示当前系统中以 RPM 方式安装的所有软件列表
-qi:查看指定软件包的名称、版本、许可协议、用途描述等详细信息(--info)
-ql:显示指定的软件包在当前系统中安装的所有目录、文件列表(--list)
-qf:查看指定的文件或目录是由哪个软件包所安装的(--file)
#查看系统中安装的所有rpm软件包
[root@CentOS7-4 ~]# rpm -qa
yum-3.4.3-168.el7.centos.noarch
grub2-common-2.02-0.86.el7.centos.noarch
firewalld-filesystem-0.6.3-11.el7.noarch
setup-2.8.71-11.el7.noarch
kbd-1.15.5-15.el7.x86_64
basesystem-10.0-7.el7.centos.noarch
NetworkManager-team-1.18.8-1.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
NetworkManager-tui-1.18.8-1.el7.x86_64
tzdata-2020a-1.el7.noarch
selinux-policy-targeted-3.13.1-268.el7.noarch
glibc-common-2.17-317.el7.x86_64
kexec-tools-2.0.15-51.el7.x86_64
nspr-4.21.0-1.el7.x86_64
openssh-clients-7.4p1-21.el7.x86_64
libstdc++-4.8.5-44.el7.x86_64
audit-2.8.5-4.el7.x86_64
bash-4.2.46-34.el7.x86_64
kernel-3.10.0-1160.el7.x86_64
pcre-8.32-17.el7.x86_64
microcode_ctl-2.1-73.el7.x86_64
#检索某个软件包是否有安装
[root@localhost ~]# rpm -q samba
未安装软件包 samba
[root@localhost ~]# rpm -qa | grep -i samba
#查询某个已安装的软件包的摘要信息
[root@CentOS7-4 ~]# rpm -qi python
Name : python
Version : 2.7.5
Release : 89.el7
Architecture: x86_64
Install Date: 2023年03月28日 星期二 17时14分30秒
Group : Development/Languages
Size : 80835
License : Python
Signature : RSA/SHA256, 2020年10月15日 星期四 02时59分06秒, Key ID 24c6a8a7f4a80eb5
Source RPM : python-2.7.5-89.el7.src.rpm
Build Date : 2020年10月14日 星期三 23时09分26秒
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://www.python.org/
Summary : An interpreted, interactive, object-oriented programming language
Description :
Python is an interpreted, interactive, object-oriented programming
language often compared to Tcl, Perl, Scheme or Java. Python includes
modules, classes, exceptions, very high level dynamic data types and
dynamic typing. Python supports interfaces to many system calls and
libraries, as well as to various windowing systems (X11, Motif, Tk,
Mac and MFC).
Programmers can write new built-in modules for Python in C or C++.
Python can be used as an extension language for applications that need
a programmable interface.
Note that documentation for Python is provided in the python-docs
package.
This package provides the "python" executable; most of the actual
implementation is within the "python-libs" package.
#查看某个软件包安装的目录和文件清单
[root@CentOS7-4 ~]# rpm -ql python
/usr/bin/pydoc
/usr/bin/python
/usr/bin/python2
/usr/bin/python2.7
/usr/libexec/platform-python
/usr/share/doc/python-2.7.5
/usr/share/doc/python-2.7.5/LICENSE
/usr/share/doc/python-2.7.5/README
/usr/share/man/man1/python.1.gz
/usr/share/man/man1/python2.1.gz
/usr/share/man/man1/python2.7.1.gz
#系统中的某个文件是由哪一个软件包生成的
[root@localhost ~]# which vim
/usr/bin/vim
[root@localhost ~]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.629-8.el7_9.x86_64
-qpi:查看指定软件包的名称、版本、许可协议、用途描述等详细信息。
-qpl:查看该软件包准备要安装的所有目标目录、文件列表。
-i:在当前系统中安装(Install)一个新的 RPM 软件包。
-e:卸载指定名称的软件包。
-U:检查并升级系统中的某个软件包,若该软件包原来并未安装,则等同于“-i”选项。
-F:检查并更新系统中的某个软件包,若该软件包原来并未安装,则放弃安装。
-h:在安装或升级软件包的过程中,以“#”号显示安装进度。
-v:显示软件安装过程中的详细信息。
--force:强制安装某个软件包,当需要替换已安装的软件包及文件,或者安装一
个比当前使用的软件版本更旧的软件时,可以使用此选项。
--nodeps:在安装或升级、卸载一个软件包时,不检查与其他软件包的依赖关系
[root@CentOS7-4 ~]# which ifconfig
/usr/sbin/ifconfig
[root@CentOS7-4 ~]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.25.20131004git.el7.x86_64
[root@CentOS7-4 ~]# rpm -qpi net-tools-2.0-0.25.20131004git.el7.x86_64
#安装
[root@localhost ~]# rpm -ivh /mnt/Packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh /mnt/Packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
#更新,软件包必须已经安装才可更新
[root@localhost ~]# rpm -Fvh /mnt/Packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
[root@localhost ~]# rpm -e net-tools
#可以结合 --nodeps 忽略依赖
#使用MD5校验
[root@localhost ~]# md5sum apache-tomcat-8.5.16.tar.gz ed752991f01e270ccfc7b4e8686f4f3c
apache-tomcat-8.5.16.tar.gz
#使用sha256校验
[root@localhost ~]# sha256sum apache-tomcat-8.5.16.tar.gz 939fb7c9fae3298dd0ccb4724b9c943c524e8af287531c8f3bbec0707e5780f1 apache-tomcat-8.5.16.tar.gz
[root@CentOS7-4 ~]# yum -y install gcc gcc-c++ make
[root@CentOS7-4 ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[root@CentOS7-4 ~]# make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[root@CentOS7-4 ~]# ll httpd-2.4.9.tar.gz
-rw-r--r-- 1 root root 6784016 3月 29 18:02 httpd-2.4.9.tar.gz
[root@CentOS7-4 ~]# yum -y install pcre-devel apr-devel expat-devel libdb-devel cyrus-sasl-devel openldap-devel apr-util-devel
[root@CentOS7-4 ~]# tar zxf httpd-2.4.9.tar.gz -C /usr/src/
[root@CentOS7-4 ~]# ls /usr/src/
debug httpd-2.4.9 kernels
[root@CentOS7-4 ~]# cd /usr/src/httpd-2.4.9/
[root@CentOS7-4 httpd-2.4.9]# ./configure --prefix=/usr/local/apache
[root@CentOS7-4 httpd-2.4.9]# make
[root@CentOS7-4 httpd-2.4.9]# make install
[root@CentOS7-4 httpd-2.4.9]# vi /usr/local/apache/conf/httpd.conf
[root@CentOS7-4 httpd-2.4.9]# /usr/local/apache/bin/apachectl start
yum list [软件名]...
yum info [软件名]...
yum search <关键词>...
yum grouplist <包组名>...
yum groupinfo <包组名>...
yum install <软件名>...
yum groupinstall <包组名>...
yum update <软件名>...
yum groupupdate <包组名>...
yum remove <软件名>...
yum groupremove <包组名>...
yum makecache
yum clean all
基本设置:/etc/yum.conf
仓库设置:/etc/yum.repos.d/*.repo
日志文件:/var/log/yum.log
使用本地ISO文件作为yum仓库
[root@CentOS7-4 ~]# mkdir /ISO #创建一个ISO文件
[root@CentOS7-4 ~]# mount /dev/cdrom /ISO #把/dev/cdrom 挂载到ISO文件
mount: /dev/sr0 写保护,将以只读方式挂载
[root@CentOS7-4 yum.repos.d]# vi 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:///ISO #修改此处
gpgcheck=1
enabled=1 #开启
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@CentOS7-4 yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-x86_64-kernel.repo
[root@CentOS7-4 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@CentOS7-4 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
c7-media | 3.6 kB 00:00:00
(1/4): c7-media/group_gz | 153 kB 00:00:00
(2/4): c7-media/filelists_db | 3.3 MB 00:00:00
(3/4): c7-media/primary_db | 3.3 MB 00:00:00
(4/4): c7-media/other_db | 1.3 MB 00:00:00
元数据缓存已建立
#例如vim和net-tools
[root@CentOS7-4 yum.repos.d]# yum -y install vim net-tools wget
[root@CentOS7-4 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@CentOS7-4 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
[root@CentOS7-4 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@CentOS7-4 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): extras/7/x86_64/other_db | 149 kB 00:00:00
(2/6): extras/7/x86_64/filelists_db | 276 kB 00:00:00
(3/6): updates/7/x86_64/other_db | 1.3 MB 00:00:00
(4/6): base/7/x86_64/other_db | 2.6 MB 00:00:01
(5/6): base/7/x86_64/filelists_db | 7.2 MB 00:00:04
(6/6): updates/7/x86_64/filelists_db | 11 MB 00:00:06
元数据缓存已建立
[root@CentOS7-4 yum.repos.d]# vi 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:///ISO
gpgcheck=1
enabled=0 #修改此处-关闭
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#例如vim和net-tools
[root@CentOS7-4 yum.repos.d]# yum -y install vim net-tools wget