本文需不断更新,根据自身掌握情况扩充
-----------------------------------------------------------------------------------------------------------
一、YUM
概述:yum是通过系统中配置的源repo信息,通过连接互联网管理RPM包的shell命令。
yum的关键之处是要有可靠的repository,顾名思义这就是软件的仓库,它可以是http或者ftp站点,也可以是本地的软件池,但是必须包含rpm的header,rpm的header包括了rmp的各种信息,包括描述、功能、提供的文件、依赖性等,正是收集了这些信息,才能自动化的完成余下的任务。yum本身就是运行在linux上的自动管理安装包的系统。yum 的理念是使用一个中心仓库(repository)管理一部分甚至一个distribution 的应用程序相互关系,根据计算出来的软件依赖关系进行相关的升级、安装、删除等等操作,减少了Linux 用户一直头痛的dependencies 的问题。
系统中配置的repo源位置在 /etc/yum.repos.d/ 文件夹内,其中很多源作为合并使用.
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
一些软件,例如Mysql,可以下载repository文件,然后更新到自己的repository中。
Mysql官网下载repo文件。
使用RPM命令更新自己的库
[root@localhost tmp]# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
更新后还可以根据版本进行修改
[root@localhost tmp]# yum repolist all | grep -i mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 185
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 123
mysql-tools-community-source MySQL Tools Community - Sour disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 229
mysql80-community-source MySQL 8.0 Community Server - disabled
比如说,我们想装mysql57
yum-config-manager --disable mysql80-community/x86_64
yum-config-manager --enable mysql57-community/x86_64
yum install -y mysql57-community
1. 列出所有安装软件
yum list installed
2. 查询, 例如查询 ifconfig属于哪个包
yum search php
3. 安装
yum install -y php.3.2.xxxx
4. 卸载
yum remove -y xxx
5. 通过命令查找包.
例如, 想使用semanage 发现命令不存在,
yum install semanage #又找不到
这时可以用:
yum provides semanage or yum whatprovides semanage #找到该命令对应的包,然后只需要安装这个工具集的包就可以了.
Matched from:
Filename : /usr/sbin/semanage
policycoreutils-python-utils-2.8-16.1.el8.noarch : SELinux policy core python utilities
Repo : rhel-8-baseos-rhui-rpms
Matched from:
Filename : /usr/sbin/semanage
policycoreutils-python-utils-2.9-3.el8.noarch : SELinux policy core python utilities
Repo : rhel-8-baseos-rhui-rpms
Matched from:
Filename : /usr/sbin/semanage
policycoreutils-python-utils-2.9-3.el8_1.1.noarch : SELinux policy core python utilities
Repo : rhel-8-baseos-rhui-rpms
Matched from:
Filename : /usr/sbin/semanage
policycoreutils-python-utils-2.9-9.el8.noarch : SELinux policy core python utilities
Repo : rhel-8-baseos-rhui-rpms
Matched from:
Filename : /usr/sbin/semanage
#yum -y install policycoreutils-python-utils-2.8-16.1.el8.noarch 即可
借鉴于:CentOS yum 命令详解 - 古I月 - 博客园
二、RPM
1.查询
rpm -qa | grep mysql --查询系统里是否安装
rpm -q mysql
rpm -qa --查询目前系统安装的所有软件包
2.安装
rpm -i xxx.rpm --安装xxx.rpm包
rpm -iv xxx.rpm --安装xxx.rpm包,并显示安装的过程
rpm -ivh xxx.rpm --安装xxx.rpm包,并显示安装的过程,并显示标记
3.卸载
rpm -e xxx --卸载xxx软件,注意没有包名
4.升级软件
rpm -Uvh xxx.rpm --注意是大写U,rpm会自动卸载低版本软件
如果老版本软件的配置文件通新版本的不兼容,rpm会自动将其保存为另外一个文件,用户会看到下面的信息:
saving /etc/example.conf as /etc/example.conf.rpmsave
如果这次升级的软件包比现有的已经安装软件包版本低,会报错
另外如果用户要安装老版本的软件,用户就会看到下面的出错信息:
# rpm -Uvh xxx.rpm
xxx packag xxx-2.0-l(which is newer) is already installed
error:xxx.rpm cannot be installed
如果用户要强行安装就使用-oldpackage参数。
5. 异常处理
#a. xxx.rpm Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
原因:这是由于yum安装了旧版本的GPG keys造成的
解决办法:后面加上 --force --nodeps
--force
Same as using --replacepkgs, --replacefiles, and --oldpackage.
--force
Same as using --replacepkgs, --replacefiles, and --oldpackage.