1 替换成阿里源

1.1 进入yum源配置文件所在文件夹

1
cd /etc/yum.repos.d/

1.2 首先备份

1
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

1.3 下载aliyun的yum源配置文件,放入/etc/yum.repos.d/(操作前请做好相应备份)

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

1.4 运行yum makecache生成缓存

1
2
3
4
5
yum clean all   # 清除缓存
rm -rf  /var/cache/yum/  # 清除缓存
yum makecache  # 生成缓存
 
yum clean all && rm -rf  /var/cache/yum/ && yum makecache

2 替换成公司源

2.1 进入yum源配置文件所在文件夹

1
cd /etc/yum.repos.d/

2.1 首先备份

1
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

3.3 打开/etc/yum.repos.d/CentOS-Base.repo 修改其内容

1
2
3
4
5
6
7
8
vim /etc/yum.repos.d/CentOS-Base.repo
 
[base]
name=sw-CentOS-$releasever - Base
baseurl=http://yum.swomc.xyz/centos/$releasever/os/$basearch/
http://yum.swomc.net/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://yum.swomc.net/centos/RPM-GPG-KEY-CentOS-$releasever

4.4 运行yum makecache生成缓存

1
yum makecache

5.公司服务器yum源

1.CentOS-Base.repo

1
2
3
4
5
6
7
vim CentOS-Base.repo
[base]
name=sw-CentOS-$releasever - Base
baseurl=http://yum.swomc.xyz/centos/$releasever/os/$basearch/
        http://yum.swomc.net/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://yum.swomc.net/centos/RPM-GPG-KEY-CentOS-$releasever

2.custome.repo

1
2
3
4
5
6
7
8
vim custome.repo
[custome]
name=sw-Custome-$releasever - Custome
baseurl=http://yum.swomc.xyz/custome/Packages
        http://yum.swomc.net/custome/Packages
 
enabled=1
gpgcheck=0

3.epel.repo

1
2
3
4
5
6
7
8
9
vim epel.repo
[epel]
name=sw-Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://yum.swomc.xyz/epel/$releasever/$basearch
        http://yum.swomc.net/epel/$releasever/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever

4.获取 GPG 密钥失败:[Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

1
2
cd /etc/pki/rpm-gpg/
wget https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7

  

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
yum list installed    # 显示已经安装的软件包
 
yum list vim  # 查找可以安装的软件包 (以 vim 为例)
 
yum -y install vim  # 安装软件包 (以 vim 为例)
 
yum deplist vim  # 列出软件包的依赖 (以 vim 为例)
 
yum info vim   # info 显示软件包的描述信息和概要信息(以 vim 为例)
 
yum update vim  # 升级某一个软件包 ,(以 vim 为例)
 
yum check-update   # 检查可更新的程序
 
yum remove vim  # 卸载软件包 (以 vim 为例)