0
点赞
收藏
分享

微信扫一扫

linux软件包管理和使用 yum

1,什么是YUM

linux软件包管理和使用 yum_centos

 

 2,yum源是什么

linux软件包管理和使用 yum_清除缓存_02

 

 

[root@host-234 liexin521]# ll /etc/yum.repos.d/
总用量 92
-rw-r--r--. 1 root root 1664 11月 23 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11月 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 11月 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 11月 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 11月 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 11月 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 11月 23 2020 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 1919 3月 9 2021 docker-ce.repo
-rw-r--r--. 1 root root 1358 9月 5 2021 epel.repo
-rw-r--r--. 1 root root 1457 9月 5 2021 epel-testing.repo
-rw-r--r--. 1 root root 773 5月 17 16:48 gitlab_gitlab-ce.repo
-rw-r--r--. 1 root root 173 10月 12 2020 google-chrome.repo
-rw-r--r--. 1 root root 669 5月 2 2019 ius-archive.repo
-rw-r--r--. 1 root root 591 5月 2 2019 ius.repo
-rw-r--r--. 1 root root 669 5月 2 2019 ius-testing.repo
-rw-r--r--. 1 root root 85 11月 30 2016 jenkins.repo
-rw-r--r--. 1 root root 756 4月 19 2021 mariadb.repo
-rw-r--r--. 1 root root 474 4月 25 2018 nodesource-el7.repo
-rw-r--r--. 1 root root 472 9月 9 2015 nodesource-el.repo
-rw-r--r--. 1 root root 130 4月 19 2021

 

linux软件包管理和使用 yum_centos_03

 

 

vim /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

 

 

CentOS 镜像使用帮助

​​ https://mirrors.tuna.tsinghua.edu.cn/help/centos/​​

请注意,CentOS 8 (非 Stream 版)已提前进入 EOL 停止服务阶段,因此镜像已被官方移动。如果您正在寻找关于这些系统的镜像,请参考 centos-vault 的帮助。

 

该文件夹只提供 CentOS 7 与 8,架构仅为 ​​x86_64​​ ,如果需要较早版本的 CentOS,请参考 centos-vault 的帮助,若需要其他架构,请参考 centos-altarch 的帮助。

 

建议先备份 /etc/yum.repos.d/ 内的文件。

 

然后编辑 /etc/yum.repos.d/ 中的相应文件,在 ​mirrorlist=​ 开头行前面加 ​#​ 注释掉;并将 ​baseurl=​ 开头行取消注释(如果被注释的话)。 对于 CentOS 7 ,请把该行内的域名(例如​mirror.centos.org​)替换为 ​mirrors.tuna.tsinghua.edu.cn​。 对于 CentOS 8 ,请把 ​mirror.centos.org/$contentdir​ 替换为 ​mirrors.tuna.tsinghua.edu.cn/centos​

 

以上步骤可以被下方的命令一步完成

 

# 对于 CentOS 7
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

# 对于 CentOS 8
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

 

 

注意其中的​​*​​通配符,如果只需要替换一些文件中的源,请自行增删。

 

注意,如果需要启用其中一些 repo,需要将其中的 ​​enabled=0​​​ 改为 ​​enabled=1​​。

 

最后,更新软件包缓存

 

sudo yum makecache

 

vim epel.repo

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=http://download.example/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=http://download.example/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place it's address here.
#baseurl=http://download.example/pub/epel/7/source/tree/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch&infra=$infra&content=$contentdir
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

 

 配置:epel源:

yum install -y epel-release

 

EPEL 镜像使用帮助

​​https://mirrors.tuna.tsinghua.edu.cn/help/epel/​​

EPEL(Extra Packages for Enterprise Linux)是由Fedora Special Interest Group维护的Enterprise Linux(RHEL、CentOS)中经 常用到的包。

下面以CentOS 7为例讲解如何使用本镜像站的epel镜像。CentOS 8同样可用该方法。

首先从CentOS Extras这个源(​​本镜像站​​也有镜像)里安装epel-release:

yum install epel-release

 

修改​​/etc/yum.repos.d/epel.repo​​​,将​​mirrorlist​​​和​​metalink​​开头的行注释掉。

接下来,取消注释这个文件里​​baseurl​​​开头的行,并将其中的​​http://download.fedoraproject.org/pub​​​替换成​​https://mirrors.tuna.tsinghua.edu.cn​​。

可以用如下命令自动替换:(来自 https://github.com/tuna/issues/issues/687)

sed -e 's!^metalink=!#metalink=!g' \
-e 's!^#baseurl=!baseurl=!g' \
-e 's!//download\.fedoraproject\.org/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
-e 's!//download\.example/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
-e 's!http://mirrors!https://mirrors!g' \
-i /etc/yum.repos.d/epel*.repo

 

修改结果如下:(仅供参考,不同版本可能不同)

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

 

运行 ​​yum update​​ 测试一下吧。

 

linux软件包管理和使用 yum_清除缓存_04

 

 

 更换阿里云源

1.进入到yum的源目录下

cd /etc/yum.repos.d/

2.将原来的CentOS-Base.repo进行备份

mv CentOS-Base.repo CentOS-Base.repo_back

3.下载替换阿里源

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

5.生成缓存

yum clean all  清除缓存
yum makecache 生成缓存

 

 

 

 

yum相关命令

yum常用命令

  • 1. 列出所有可更新的软件清单命令:yum check-update
  • 2. 更新所有软件命令:yum update
  • 3. 仅安装指定的软件命令:yum install <package_name>
  • yum reinstall 重新安装
  • 4. 仅更新指定的软件命令:yum update <package_name>
  • 5. 列出所有可安裝的软件清单命令:yum list
  • 6. 删除软件包命令:yum remove <package_name>
  • 7. 查找软件包命令:yum search <keyword>
  • 查找:yum provides 根据文件。命令。库文件,搜索对应的软件包
  • 缓存yum源软件仓库,xml元数据文件 yum makecache
  • 8. 清除缓存命令:
  • yum clean packages: 清除缓存目录下的软件包
  • yum clean headers: 清除缓存目录下的 headers
  • yum clean oldheaders: 清除缓存目录下旧的 headers
  • yum clean,yum clean all(= yum clean packages; yum clean oldheaders) :清除缓存目录下的软件包及旧的 headers

 

yum install -y bash-completion*   命令不全工具
yum clean packages 只清除缓存的软件包

 

linux软件包管理和使用 yum_清除缓存_05

linux软件包管理和使用 yum_清除缓存_06

linux软件包管理和使用 yum_centos_07

包组相关指令:

linux软件包管理和使用 yum_linux_08

一次性安装常用软件开发工具
yum -y group install Development tools或者 yum group install Development tools

 

全局配置文件:

/etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
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

linux软件包管理和使用 yum_centos_09

 

 

YUM 签名检查机制

linux软件包管理和使用 yum_清除缓存_10

 

YUM更新软件包

linux软件包管理和使用 yum_清除缓存_11

 

 删除软件包

linux软件包管理和使用 yum_linux_12

 

举报

相关推荐

0 条评论