这里就是重点来了,如何解决本次的软件源暂时无法使用的问题呢? 那就是提前换一个可以使用的软件源。
这里需要用到代码编辑器和SFTP软件,如果没有安装,建议参考:
【云计算的1024种玩法】ECS和轻量应用服务器的远程控制入门
RHEL、CentoS
修改 /etc/yum.repos.d/ 目录下的文件,例如:CentOS-Base.repo 、epel.repo 等,这里以修改 CentOS 7 本身的软件源文件 CentOS-Base.repo 为例:
将
CentOS-Base.repo 修改为
CentOS-Base.repo.old
然后创建一个新的
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-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
然后运行 :
yum makecache
更新软件源缓存即可。
等问题修复,将该文件删除并将 CentOS-Base.repo.old 重新命名回来并更新缓存即可。
其他 CentOS 版本可以参考:
https://mirror.tuna.tsinghua.edu.cn/help/centos/
Debian、Ubuntu
修改
/etc/apt/sources.list 文件,重命名为
/etc/apt/sources.list.old
然后重新创建
/etc/apt/sources.list 文件,内容为:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/OS/ CODE-proposed main restricted universe multiverse
注: 其中,
OS 代表 debian 或者 ubuntu,
CODE 代表发型代号,例如 Ubuntu 18.04 是 artful,Debian 9 是 stretch
展示一下 Ubuntu 16.04 的清华源替换方式:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
等问题修复,将该文件删除并将 /etc/apt/sources.list.old 重新命名回来并更新缓存即可。
使用阿里云提供的默认软件源的话,走的是 ECS 的内网速度更加的快而且走的公网也更加安全可靠。
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。