Skip to content Skip to main navigation Skip to footer

Linux/ubuntu:如何更改apt-get源

当ubuntu系统默认的官方更新源下载速度慢或者宕机的情况下,我们需要更改到其它的第三方软件包更新源,比如163,阿里云等。

本文将会讲述如何在ubuntu系统下,更改默认的ubuntu官方源到aliyun 上。

方法一:在图形界面下,打开“软件包管理中心”,在“软件源” 中选择”中国的服务器“下的”mirros.aliyun.com“, 系统会自动根据ubuntu的不同版本来选择软件源。

方法二:针对ubuntu 服务器版的系统 或者没有安装GUI的ubuntu 系统,可以通过更改配置文件的方法来实现。
1# 备份/etc/apt/sources.list 文件, 输入下面的命令:

cp /etc/apt/sources.list /etc/apt/sources.list.bak

2# 使用vi 编辑器打开 /etc/apt/sources.list 文件,删除所有的旧的软件源或者将下面相应的条目添加到文件的最前面:
根据你当前的ubuntu版本,来选择相应的条目:

xenial (16.04)

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse


wily (15.10)

deb http://mirrors.aliyun.com/ubuntu/ wily main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ wily-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ wily-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ wily-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ wily-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ wily main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ wily-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ wily-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ wily-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ wily-backports main restricted universe multiverse


vivid (15.04)

deb http://mirrors.aliyun.com/ubuntu/ vivid main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ vivid-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ vivid-backports main restricted universe multiverse


trusty(14.04)

  deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

 

Quantal(12.10)

deb http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse

 

Precise(12.04)

  deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse        


Oneiric(11.10)

deb http://mirrors.aliyun.com/ubuntu/ oneiric main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ oneiric-security main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ oneiric-updates main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ oneiric-proposed main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ oneiric-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ oneiric main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ oneiric-security main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ oneiric-updates main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ oneiric-proposed main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ oneiric-backports main restricted universe multiverse

          
Natty(11.04)

 deb http://mirrors.aliyun.com/ubuntu/ natty main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ natty-security main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ natty-updates main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ natty-proposed main restricted universe multiverse
  deb http://mirrors.aliyun.com/ubuntu/ natty-backports main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ natty main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ natty-security main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ natty-updates main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ natty-proposed main restricted universe multiverse
  deb-src http://mirrors.aliyun.com/ubuntu/ natty-backports main restricted universe multiverse

3# 保存退出后,执行apt-get update 命令来检测是否能够正常更新软件包。

 $ sudo apt-get update