Linux下rpm&yum&apt-get

RPM简介

RPM命名“RedHat Package Manager”,简称则为RPM。属于Red Hat阵营的,与其并列的则是debian。centos中大部分我们安装都是使用yum install,而debian的Ubuntu中我们大部分使用的就是apt-get了。两大阵营、

优点:RPM会将软件包信息记录在Linux主机的数据库中,/var/lib/rpm 每一个RPM包都是编译好的(二进制安装),方便查询本地安装版本和升级卸载。

缺点:软件信息包安装的环境必须与打包时的环境一致或相当。必须安装了软件的依赖软件,例如docker必须将docker包依赖的包一并安装才能正常使用docker,RPM有属性依赖的问题。

RPM包命名

软件名称-版本号-发布次数.适合linux系统.硬件平台.rpm
例如:docker-ce-19.03.12-3.el7.x86_64.rpm

看下当前系统版本 cat /etc/redhat-release centos查看方式
lsb_release -a ubuntu查看方式

RPM的一些操作方式

-i 表示安装

-v表示查看更详细的安装信息画面

-h以安装信息栏显示安装进度

-U更新软件,若系统中没有这个软件则安装

-F更新系统已安装的某个软件,如果不存在则不会安装

-e卸载。卸载需要注意的是从上层往下卸载,不然卸载可能会出问题,很der (所以不是万不得已就用yum别用rpm)

  • 安装 >>>> rpm -ivh package-name.rpm
  • 升级 >>>> rpm -Uvh package-name.rpm
  • 升级已安装 >>>> rpm -Fvh package-name.rpm
  • 强制安装 >>>> rpm -Uvh --force --nodeps rpms/*.rpm
  • 卸载 >>>> rpm -e gcc

RPM查询

rpm {-q|–query} [select-options] [query-options] 常用参数说明:

-a:all,列出已经安装在本机的所有软件(Query all instaled packages.)

-p:package,查询一个RPM文件的信息(Query an (uninstalled) package. )

-f:file,由后面接的文件名称找出该文件属于哪狐假虎威已安装的软件(Query package owning file.)

-i:information,列出该软件的详细信息,包含开发商、版本与说明等

-l:list,列出该软件所有的文件与目录所在完整文件名(List file in package)

-c:configuration,列出该软件的所有设置文件(找出在/etc/下面的文件名而已)(List only configuration files)

-d:documentation,列出该软件所有的帮助文档(List only documentation files)

-R:required,列出与该软件有关的依赖软件所含的文件(List capabilities on which this depends.)

  • 如果下载了一个rpm想看对应的依赖文件 >>>>> rpm -qpR docker-ce-19.03.12-3.el7.x86_64.rpm (这个rpm已经下载到本地了)

YUM

YUM通过依赖rpm软件包管理器

  • yum的配置文件在 /etc/yum.conf
  • yum可以配置多个Repository 源
  • 自动解决增加或删除rpm包时遇到的依赖性问题
  • 需要联网才能用
  • /var/lib/yum 是yum的安装下载目录,存储历史信息,软件信息db索引等等、

当你想安装一个软件 yum install wget 需要访问/etc/yum.repos.d/*.repo 找到配置的源端(包从源端下),从源读取说明文件XXX.xml然后存储xml到本地 /var/cache/yum中通过xml文件知道需要安装的依赖程序包在server的具体位置,然后去server下载这个包就OK了。

对于server端要提前存储包以及rpm数据库文件中程序包之间的依赖关系数据,生成对应的依赖关系和所需文件在本地存放位置的说明文件XXX.xml 存放到 /path/repodata目录供客户端获取。

  • /etc/yum.repos.d/*.repo中会有多个配置文件,yum会从里面依次查找,因此容器名称不要重复
  • 如果修改了*.repo配置文件,那么最好清除一下相关数据 yum clean all 避免本机列表与源对应出现问题。
[base]
name=CentOS-7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

[base]:代表容器的名字。中括号一定要存在,里面的名称可以随意起,但不能有两个相同的容器名称,否则yum会不知道去哪里找容器相关软件列表清单文件。配置的baseurl路径才是最重要的。
name:只是说明一下这个容器的意义而已,重要性不高。
mirrorlist:列出这个容器可以使用的镜像站点,如果不想使用可以批注掉这一行。
baseurl:这个最重要,因为后面接的就是容器的实际网址。mirrorlist是由yum程序自行去找镜像站点,baseurl则是指定固定的一个容器网址。
enable=1:启动这个容器,默认值也为1。关闭这个容器可以设置enable=0。
gpgcheck=1:指定是否需要查阅RPM文件内的数字证书。
gpgkey:数字证书的公钥文件所在位置,使用默认值即可。

YUM操作

  • yum list pam* 列出以pam开头的软件名
  • yum list updates 列出可供本机更新的软件列表。
  • yum clean all 清除对应关系 yum makecache 缓存对应关系
  • yum install -y wget 安装软件
  • yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 添加源
  • yum remove wget 卸载
  • yum update [软件] 升级整个系统/软件

yum -y update 升级所有包,改变软件设置和系统设置,系统版本内核都升级
yum -y upgrade 升级所有包,不改变软件设置和系统设置,系统版本升级,内核不改变
已经上线的用yum -y upgrade 比较稳
全新的用yum -y update 会更好

yum源配置

对应配置路径:/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-7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

关于没有互联网的环境下,如果想安装软件就需要提前下载rpm包进行安装了,以docker为例。
安装详情:https://blog.csdn.net/finalheart/article/details/107741251

apt-get

这个是debian-Ubuntu下的包管理方式类比yum、跟yum的道理是一样的,本地记录软件信息和源端的对应关系。

apt-get update 命令会扫描每一个软件源服务器,并为该服务器所具有软件包资源建立索引文件,存放在本地的/var/lib/apt/lists/目录中。 使用apt-get执行安装、更新操作时,都将依据这些索引文件,向软件源服务器申请资源。因此,在计算机设备空闲时,经常使用“apt-get update”命令刷新软件源,是一个好的习惯。

  • 软件源配置文件 /etc/apt/sources.list 和 /etc/apt/sources.list.d/*.list 列出了镜像站点地址。
  • 软件信息索引文件存放到 /var/lib/apt/lists下,apt-get update 从/etc/apt/sources.list更新的就放到这里。
  • /var/cache/apt/archives 已经下载到的软件包都放在这里(用 apt-get install 安装软件时,软件包的临时存放路径)
  • /var/lib/dpkg/available是软件包的描述信息。
  • apt-get install 会下载并安装相应的包。

deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial main

apt-get操作

  • apt-get update 更新源索引信息和依赖对应关系等到/var/lib/apt/lists
  • apt-get upgrade 更新已安装并可更新的软件(一键升级)
  • apt-get dist-upgrade 升级系统到相应的发行版(如果有依赖变化会自己解决,比较危险)
  • apt-get install wget 安装包。
  • apt-get remove wget 卸载一个已安装的软件包(保留配置文件)
  • apt-get purge wget 移除软件包(删除配置信息)
  • apt-get autoclean 删除已经删掉的软件(定期运行优化磁盘空间)
  • apt0get clean 已安装的软件包 .deb文件会被一并删除 去/var/cache/apt/archives目录看执行结果

APT的/etc/apt/sources.list设置

下面这个配置是Ubuntu阿里云服务器上面的配置

deb/deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial main
仓库-----地址-----发行版本-----软件包分类

deb 档案类型为二进制预编译软件包,一般我们所用的档案类型。
deb-src档案类型为用于编译二进制软件包的源代码。

main: 完全的自由软件。
restricted: 不完全的自由软件。
universe: Ubuntu官方不提供支持与补丁,全靠社区支持。
multiverse:非自由软件,完全不提供支持和补丁。

## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial main

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates main

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial universe
deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
# deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial multiverse
# deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial multiverse
# deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates multiverse
# deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ xenial-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security main
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security main
deb http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security universe
deb-src http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security universe
# deb http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security multiverse
# deb-src http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security multiverse
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值