1. 为什么要替换软件安装源?
Ubuntu默认的软件安装源是 http://archive.ubuntu.com
,在国内访问速度很慢。
Debian(Ubuntu是Debian的衍生品)的默认软件安装源是 http://deb.debian.org
,在国内访问也很慢。
如果换成国内的软件安装源,能够节省很多时间,因此安装Ubuntu/Debian系统后建议先进行软件安装源的替换。
本文中,我们的系统为Ubuntu14.04.5(大版本别名trusty),计划换成Ubuntu官方中国的安装源。
除了Ubuntu官方中国的安装源,可选的国内安装源还有中科大、清华、阿里、腾讯、网易等等。
1 | http://cn.archive.ubuntu.com |
更多安装源可以参考ubuntu 14.04source
其他版本的Ubuntu修改方法类似,不同之处可以参考源列表。
Debian和Ubuntu的国内安装源域名相同,只不过是域名后面的路径不同。
2. Ubuntu14更换安装源
1、备份源列表文件
1 | sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak |
2、编辑源列表文件
1 | sudo sed -i 's#http://archive.ubuntu.com#http://cn.archive.ubuntu.com#g' /etc/apt/sources.list |
修改后的 sources.list 的内容为:
1 | deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse |
ubuntu14的别名是trusty,所以souces.list中出现了很多trusty,其他版本的ubuntu就不是trusty了。
3、更新资源包
1 | sudo apt-get update |
如果报错Error connecting: Could not connect: Connection refused
解决方法参考:
- “Unable to connect” error with apt-get?
- apt-get update Error connecting Could not connect Connection refused
4、更新软件
1 | sudo apt-get upgrade |
3. Debian更换安装源
参考文档:
Debian操作更换安装源,和Ubuntu操作更换安装源方法基本相同。
1 | sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak |
对于新版的不包含 sources.list 文件的Debian系统,需要替换 debian.sources 文件中的内容。
1 | sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources |
4. Ubuntu/Debian配置时间同步
1 | sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime |
如果是在容器中操作ntpdate time.windows.com
,可能会报错ntpdate[542]: step-systime: Operation not permitted
解决办法:启动容器时直接挂载宿主机的/etc/localtime
1 | docker run --name test -d \ |