【Linux笔记】更换yum源和yum命令

Centos环境中,执行如下操作时

yum install -y net-tools 安装网络相关命令

报错:

参考博文,更换源:

yum install net-tools报错解决方法-优快云博客

centos7的yum命令无法使用解决方案_centos7 yum不可用-优快云博客

更换yum源

1、将yum源相关的文件移动到共享文件夹下

mv /etc/yum.repos.d/CentOS-Base.repo /mnt/hgfs/shared_files

2、Window下查看并修改文件内容

原文件内容:

# 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-$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-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-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirrors.aliyun.com/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://mirrors.aliyun.com/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://mirrors.aliyun.com/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://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3、将修改后的文件移动到/etc/yum.repos.d

mv /mnt/hgfs/shared_files/CentOS-Base.repo /etc/yum.repos.d 

4、清理yum缓存并更新

yum clean all    #清除缓存


yum makecache    #一般用于创建或更新yum的仓库缓存;此处重新创建缓存

yum update

CentOS 7官方于2024/6/30不在维护,找不到相关源了;

清华镜像网址上也已经找不到相关源了。

阿里云镜像网站上目前还有,兴许哪天也会被删除。

这里推荐将相关源下载到本地,然后参考博文,使用本地源配置yum源:

Centos7配置本地Yum源以及网络YUM源(保姆级)_centos7yum源-优快云博客


yum介绍

Yellowdog Updater, Modified是Linux系统中基于RPM包管理的自动更新程序和包管理器,它主要被用于Fedora、CentOS、RHEL(Red Hat Enterprise Linux)等基于RPM的Linux发行版上

1、安装软件包

        yum install packagename1 [ packagename2 ...]

2、更新软件包

        yum update [packagename]: 默认更新所有可更新软件包

3、卸载软件包

        yum remove packagename

4、搜索软件包

        yum search keyword: 搜索所有包含“keyword”关键字的软件包

5、查看软件包信息

        yum info packagename: 查看已安装的软件包信息

        yum info available packagename: 查看可安装的软件包信息

6、列出软件包

        yum list installed: 列出已安装的

        yum list available: 列出可安装的

        yum list installed | grep packagename: 列出所有已安装的与packagename有关的

7、清理缓存

        yum clean all

8、配置yum仓库

        编辑 /etc/yum.repos.d/目录下的 .repo文件:定义了yum从哪里下载软件包和元数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值