Linux软件包管理

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


一、获取程序包途径

  • 开源镜像站
http://mirrors.aliyun.com
http://mirrors.sohu.com
http://mirrors.sohu.com/centos/7.5.1804/os/x86_64/Packages/
http://mirrors.163.com
  • epel,提供centos众多额外的第三方包,可信任的第三方软件包组织
http://mirrors.sohu.com/fedora-epel/7/x86_64/Packages/
https://mirrors.aliyun.com/epel/7/x86_64/Packages/m/
  • 搜索引擎
http://www.rpmfind.net/linux/mageia/distrib/7/x86_64/media/core/release/lrzsz-0.12.21-22.mga7.x86_64.rpm

二、rpm命令

rpm命令:rpm  [OPTIONS]  [PACKAGE_FILE]
# i表示安装 v显示详细过程 h以进度条显示,每个#表示2%进度
安装软件的命令格式                rpm -ivh filename.rpm    
升级软件的命令格式                rpm -Uvh filename.rpm
卸载软件的命令格式                rpm -e filename.rpm
查询软件描述信息的命令格式         rpm -qpi filename.rpm
列出软件文件信息的命令格式         rpm -qpl filename.rpm
查询文件属于哪个 RPM 的命令格式   rpm -qf filename

案例

wget http://www.rpmfind.net/linux/mageia/distrib/7/x86_64/media/core/release/lrzsz-0.12.21-22.mga7.x86_64.rpm

#测试rpm包
[root@chaogelinux pyrpm]# rpm -ivh --test lrzsz-0.12.21-22.mga7.x86_64.rpm
警告:lrzsz-0.12.21-22.mga7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 80420f66: NOKEY
准备中...                          ################################# [100%]


[root@chaogelinux pyrpm]# rpm -ivh lrzsz-0.12.21-22.mga7.x86_64.rpm
警告:lrzsz-0.12.21-22.mga7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 80420f66: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:lrzsz-0.12.21-22.mga7            ################################# [100%]

#升级rpm包
[root@chaogelinux pyrpm]# rpm -Uvh lrzsz-0.12.21-22.mga7.x86_64.rpm
警告:lrzsz-0.12.21-22.mga7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 80420f66: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:lrzsz-0.12.21-22.mga7            ################################# [100%]


#卸载lrzsz工具
rpm -e lrzsz

三、yum工具

  • Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
  • 说到yum源就必须说到linux系统中特有的依赖关系问题,yum就是为了解决依赖关系而存在的。yum源就相当是一个目录项,当我们使用yum机制安装软件时,若需要安装依赖软件,则yum机制就会根据在yum源中定义好的路径查找依赖软件,并将依赖软件安装好。
  • YUM是“Yellow dog Updater, Modified”的缩写,是一个软件包管理器,YUM从指定的地方(相关网站的rpm包地址或本地的rpm路径)自动下载RPM包并且安装,能够很好的解决依赖关系问题。
  • YUM的基本工作机制如下: 服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。 客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。
  • Yum repository:yum仓库,存储了众多的软件包,以及相关的元数据文件
    • 文件服务器
      • ftp://
      • http://
      • nfs://
      • file://
    • yum仓库可以存在多个,自动选择软件最新的,以及优先选择离我们近的仓库下载

#yum其实也是一个rpm软件
[root@chaogelinux pyrpm]# rpm -qa yum
yum-3.4.3-163.el7.centos.noarch

三、yum客户端

/etc/yum.conf  #为所有仓库提供公共配置

[root@chaogelinux yum.repos.d]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0                                    #本地缓存是否保留,0否,1是
debuglevel=2                                #调试日志级别
logfile=/var/log/yum.log        #日志路径
exactarch=1                                    #精确系统平台版本匹配
obsoletes=1            
gpgcheck=1                                    #检查软件包的合法性
plugins=1                
installonly_limit=5                    #同时安装几个工具包
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release        


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

#请放置你的仓库在这里,并且命名为*.repo类型
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

四、yum客户端

/etc/yum.conf  #为所有仓库提供公共配置

[root@chaogelinux yum.repos.d]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0                                    #本地缓存是否保留,0否,1是
debuglevel=2                                #调试日志级别
logfile=/var/log/yum.log        #日志路径
exactarch=1                                    #精确系统平台版本匹配
obsoletes=1            
gpgcheck=1                                    #检查软件包的合法性
plugins=1                
installonly_limit=5                    #同时安装几个工具包
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release        


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

#请放置你的仓库在这里,并且命名为*.repo类型
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

五、配置yum源

  • http://mirrors.163.com/
  • https://opsx.alibaba.com/mirrors
  • http://mirrors.sohu.com/
1.备份现有repo仓库
2.下载新的repo文件
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.清空旧yum缓存,生成新的缓存
yum clean all
yum makecache

4.针对阿里云镜像,可能出现无法解析地址的异常
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

5.配置epel源
epel(RHEL 7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
epel(RHEL 5)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo

六、配置yum源

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯智能台灯

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值