Linux软件管理(保姆级教程)


一、含义

cenost7 软件管理

主要作用:安装下载 软件包(服务 命令)
(1) yum 下载安装

(2) rpm 只能安装 需要本地有包

镜像默认的源 是在国外,速度比较满

01 配置文件

vim /etc/yum.conf
cachedir=/var/cache/yum/ b a s e a r c h / basearch/ basearch/releasever //缓存目录 缓存rpm
keepcache=1 //缓存软件包, 1启动 0 关闭
debuglevel=2 //调试级别
logfile=/var/log/yum.log //日志记录位置
exactarch=1 //检查平台是否兼容
obsoletes=1 //检查包是否废弃
gpgcheck=1 //检查来源是否合法,需要有制作者的公钥信息
plugins=1 //是否启用查询
installonly_limit=5
bugtracker_url
#metadata_expire=90m //每小时手动检查元数据
#in /etc/yum.repos.d //包含repos.d目录

02 开启缓存后 会生成 rpm包 (可以直接被安装)

(1)安装 tree 并缓存包
[root@bogon updates]# yum install -y tree

(2)检查安装包位置
[root@bogon updates]# find /var/cache/yum/x86_64/7/* -type f -name “*.rpm”
/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm

03 rpm 安装

[root@bogon updates]# rpm -ivh /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
准备中… ################################# [100%]
正在升级/安装…
1:tree-1.6.0-10.el7 ################################# [100%]

二. 安装yum 源

cenost7 默认都是国外源 速度慢 需要更换位国内源

更换源就是更换 配置文件

01 配置文件

[root@bogon updates]# ll /etc/yum.repos.d/
总用量 36
-rw-r–r–. 1 root root 1664 4月 7 2020 CentOS-Base.repo
-rw-r–r–. 1 root root 1309 4月 7 2020 CentOS-CR.repo
-rw-r–r–. 1 root root 649 4月 7 2020 CentOS-Debuginfo.repo
-rw-r–r–. 1 root root 314 4月 7 2020 CentOS-fasttrack.repo
-rw-r–r–. 1 root root 630 4月 7 2020 CentOS-Media.repo
-rw-r–r–. 1 root root 1331 4月 7 2020 CentOS-Sources.repo
-rw-r–r–. 1 root root 7577 4月 7 2020 CentOS-Vault.repo
-rw-r–r–. 1 root root 616 4月 7 2020 CentOS-x86_64-kernel.repo

02 更换阿里源

(1)备份原来源文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

(2)下载阿里云源 到指定位置
[root@bogon updates]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

(3)检查
[root@bogon updates]# egrep -v '……KaTeX parse error: Expected group after '^' at position 2: |^̲#' /etc/yum.rep…releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
http://mirrors.cloud.aliyuncs.com/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS- r e l e a s e v e r − U p d a t e s − m i r r o r s . a l i y u n . c o m f a i l o v e r m e t h o d = p r i o r i t y b a s e u r l = h t t p : / / m i r r o r s . a l i y u n . c o m / c e n t o s / releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/ releaseverUpdatesmirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/updates/ b a s e a r c h / h t t p : / / m i r r o r s . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.aliyuncs.com/centos/ basearch/http://mirrors.aliyuncs.com/centos/releasever/updates/ b a s e a r c h / h t t p : / / m i r r o r s . c l o u d . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.cloud.aliyuncs.com/centos/ basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS- r e l e a s e v e r − E x t r a s − m i r r o r s . a l i y u n . c o m f a i l o v e r m e t h o d = p r i o r i t y b a s e u r l = h t t p : / / m i r r o r s . a l i y u n . c o m / c e n t o s / releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/ releaseverExtrasmirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/extras/ b a s e a r c h / h t t p : / / m i r r o r s . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.aliyuncs.com/centos/ basearch/http://mirrors.aliyuncs.com/centos/releasever/extras/ b a s e a r c h / h t t p : / / m i r r o r s . c l o u d . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.cloud.aliyuncs.com/centos/ basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS- r e l e a s e v e r − P l u s − m i r r o r s . a l i y u n . c o m f a i l o v e r m e t h o d = p r i o r i t y b a s e u r l = h t t p : / / m i r r o r s . a l i y u n . c o m / c e n t o s / releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/ releaseverPlusmirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/centosplus/ b a s e a r c h / h t t p : / / m i r r o r s . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.aliyuncs.com/centos/ basearch/http://mirrors.aliyuncs.com/centos/releasever/centosplus/ b a s e a r c h / h t t p : / / m i r r o r s . c l o u d . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.cloud.aliyuncs.com/centos/ basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[contrib]
name=CentOS- r e l e a s e v e r − C o n t r i b − m i r r o r s . a l i y u n . c o m f a i l o v e r m e t h o d = p r i o r i t y b a s e u r l = h t t p : / / m i r r o r s . a l i y u n . c o m / c e n t o s / releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/ releaseverContribmirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/releasever/contrib/ b a s e a r c h / h t t p : / / m i r r o r s . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.aliyuncs.com/centos/ basearch/http://mirrors.aliyuncs.com/centos/releasever/contrib/ b a s e a r c h / h t t p : / / m i r r o r s . c l o u d . a l i y u n c s . c o m / c e n t o s / basearch/ http://mirrors.cloud.aliyuncs.com/centos/ basearch/http://mirrors.cloud.aliyuncs.com/centos/releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

三. 具体使用 命令

1.基本语法总会

	yum 搜索指令
		   
		   yum provides   根据文件,命令,库文件,搜索对应的软件包
		   yum search all 更详细,查找出来的内容更多 
		   yum list  列出软件仓库中可用的软件
		   yum info   列出软件包详情(轻易别用)
		  
		yum 安装指令
		  
		   yum install       安装软件只需要给出软件名称
		   yum install  -y   安装过程中分析依赖关系后, 直接安装, 无需交互 默认选择yes
		   yum localinstall  安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖
			                 (非来自.repo定义的软件仓库 后面跟路径/mnt/Packages/		   
		   yum reinstall   重新安装软件
		  
		yum软件包指令			  
		   yum check-update  #对比Linux已安装的软件和yum仓库中的软件, 有哪些需要升级
		   yum update     #更新软件 (yum update  -y #如果单独更新某个软件yum isntall  )
		   
		  
		删除软件指令 			  
		   yum erase samba -y   删除该软件包,不会删除依赖, 但是我们尽可能不要使用删除软件操作
		   yum remove samba -y  注释:rpm -e #负责删除 #尽量不删除,关闭后放着就ok
		   
		yum 仓库相关指令 			   
		   yum repolist       列出yum源可用的软件仓库 
		   yum repolist all   列出全部yum源可用和禁用的仓库			   
		   yum provides    查看这个文件或命令属于哪个包
				例如;yum provides /etc/my.cnf
				   yum provides cd
		   
		yum  缓存相关指令			  
		   yum makecache   生成yum缓存
		   yum clean all  清空 本地yum缓存 (更换了yum源一般需要清空缓存,让系统重新生yum缓存)
		   
		   #导入rpm包   yum localinstall -y 绝对路径
		   
		   注释:修改yum全局配置文件  vim /etc/yum.conf 
			  查看缓存的xml文件    ls /var/cache/yum/x86_64/7/base/
			  查看缓存软件包路径    /var/cache/yum/x86_64/7/
			  
		yum 包组相关指令		  
		   yum groups list           列出已经安装和所有可使用的软件组
		   yum groups install   安装一整个组的软件				
		   yum groups remove -y         yum删除包组
		   			   
		yum 历史记录指令
		   yum history   查看历史执行yum命令
		   yum history info N  查询历史执行yum命令ID详细信息
		   yum history undo N  撤销历史执行过的yum命令
		   
		   
		  yum 签名检查机制 
		  
			方式1: 指定公钥的位置
			方式2: 提前导入公钥
			方式3: 不进行签名验证     yum install httpd --nogpgcheck				
	
	
		rpm-具体使用选项,参数		
	rpm-安装
	
	-ivh 安装(例如:[root@bogon ~]# rpm -ivh /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm )
			(-i 安装, -v 详细信息,-h 安装进度 )安装软件包, 需要指定软件包绝对路径和rpm完整名称
			--test: 测试是否能够安装成功 (了解,测试一个软件包是否能在该系统上安装)
			--force: 强制重新安装 (了解,如果软件包存在, 强制再次安装)
			--nodeps: 忽略依赖关系,用于安装或者删除
	-Uvh 安装升级
			
	rpm -查询
	
	-q  查询指定的软件包是否安装 (例: rpm -q tree )
	-qa 查询系统中已经安装的所有rpm软件包列表 (例:rpm -qa | grep 'rpm' 可以配合grep使用)
	-ql 查询指定软件包,所安装(在)的目录,文件列表(软件内容) (例:rpm -ql tree)
	-qf 查询命令文件属于那个rpm包,(例:rpm -qf `which tree`  跟命令的绝对路径)
		以上需要熟悉
	-qi 查看指定软件的详细信息 (例:rpm -qi tree)
	-qd 查询指定软件包的帮助文档 man手册 (例: rpm -qd tree)
	-qc 查询指定软件包的配置文件
		以上了解即可
	#查询未安装的软件包信息
	rpm -qip    #查询未安装的rpm包详细信息 需要跟路径,rpm -qlp /mnt/Packages/samba-3.6.23-41.el6.x86_64.rpm
	rpm -qlp    #查询未安装的软件包会产生哪些文件
		(了解即可)
		
		
	rpm -卸载
	-e (eraser) 卸载删除指定的软件包(注意卸载包时需要先把依赖的包卸载掉,如果依赖的包是系统所必须的,那就不能
				   卸载这个包,否则会造成系统崩溃) 可以搭配--nodeps忽略依赖使用
				
	rpm 校验  (软件相关的数据库存放于 /var/lib/rpm 目录)
	rpm -aV tree (例如:S.5....T.   /usr/bin/tree 只有有5,说明内容已经被修改 md5变化)
			扩展:	S   //文件的容量大小是否被改变
					M   //文件的类型或者文件的属性是否被修改
					5   #MD5这一种指纹加密的内容已经不同 文件内容变化
					D   //装置的主/次代码已经改变
					L   //路径已经被改变
					U   //文件的所属主已被修改
					G   //文件的所属组已被修改
					T   //文件的修改时间已被改变

2.搜索软件

01 基础语法

yum 搜索指令
yum provides 根据文件,命令,库文件,搜索对应的软件包
yum search all 更详细,查找出来的内容更多
yum list 列出软件仓库中可用的软件
yum info 列出软件包详情(轻易别用)

02 搜索单个命令 文件 provides

[root@bogon updates]# yum provides wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.bupt.edu.cn

  • extras: mirrors.huaweicloud.com

  • updates: mirrors.huaweicloud.com
    wget-1.14-18.el7_6.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
    源 :base

    解释下:
    包名称: wget-1.14-18.el7_6.1.x86_64
    源 : base

##一般只用第一个 provides

3.安装 卸载

基本语法

1 直接安装 install
2 本地安装 localinstall
3 重新安装 reinstall

01 安装软件 install

[root@bogon updates]# yum install -y tree
解释下:
-y yes 安装过程中分析依赖关系后, 直接安装, 无需交互 默认选择yes

02 本地安装 yum localinstall 安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖

[root@bogon updates]# yum localinstall /var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm

03 重新安装 yum reinstall 重新安装软件

[root@bogon updates]# yum reinstall wget

04 卸载 remove

[root@bogon updates]# yum remove -y tree

4.yum 仓库相关

四 rpm 本地包管理

1.查询

01 rpm 查询
	-q  查询指定的软件包是否安装 (例: rpm -q tree )
	-qa 查询系统中已经安装的所有rpm软件包列表 (例:rpm -qa | grep 'rpm' 可以配合grep使用)
	-ql 查询指定软件包,所安装(在)的目录,文件列表(软件内容) (例:rpm -ql tree)
	-qf 查询命令文件属于那个rpm包,(例:rpm -qf `which tree`  跟命令的绝对路径)
		以上需要熟悉
	-qi 查看指定软件的详细信息 (例:rpm -qi tree)
	-qd 查询指定软件包的帮助文档 man手册 (例: rpm -qd tree)
	-qc 查询指定软件包的配置文件

2.安装

三种方式

1 直接安装 install
2 本地安装 localinstall
3 重新安装 reinstall

01 开启缓存

[root@bogon updates]# grep ‘keepcache’ /etc/yum.conf
cachedir=/var/cache/yum/ b a s e a r c h / basearch/ basearch/releasever
keepcache=1

解释下:
1 代表开启缓存
cachedir 缓存目录

02 使用yum 缓存该命令

1)安装 tree 并缓存包
[root@bogon updates]# yum install -y tree

2)检查安装包位置
[root@bogon updates]# find /var/cache/yum/x86_64/7/* -type f -name “*.rpm”
/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm

01 直接安装

[root@bogon updates]# rpm -ivh /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
准备中… ################################# [100%]
正在升级/安装…
1:tree-1.6.0-10.el7 ################################# [100%]

解释下:
		-i 安装
		-v 详细信息
		-h 安装进度
		
	注意: 安装软件包, 需要指定软件包绝对路径和rpm完整名称
02 本地安装

yum localinstall 安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖

03 重新安装

yum reinstall 重新安装软件

3.卸载

rpm -卸载
-e (eraser) 卸载删除指定的软件包(注意卸载包时需要先把依赖的包卸载掉,如果依赖的包是系统所必须的,那就不能
卸载这个包,否则会造成系统崩溃) 可以搭配–nodeps忽略依赖使用

#01 [root@aliyun ~]# rpm -e tree

  • 20
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值