Centos环境中,执行如下操作时
yum install -y net-tools 安装网络相关命令
报错:
参考博文,更换源:
更换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源:
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从哪里下载软件包和元数据