ubuntu16.04TLS软件源update

网上应该能够找到不少关于ubuntu源的设置方法,可是若是不搞清楚就随便设置的话,不只不能起到应有的效果,还会因为一些问题致使apt不可用。ubuntu

最正确的更换源的方法应该如系统提示的:阿里云

## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmplspa

这种方法有点没弄明白在/etc/apt/sources.list.d应该添加的是什么内容,若是是源文件的话,最后更改的模板又是什么做用?也没有去尝试,有时间会解决一下。rest

如下提供设置阿里源的方法,其余源也能够如法炮制:code

1. 首先查看本身的ubuntu系统的codename,这一步很重要,直接致使你更新的源是否对你的系统起效果,查看方法:blog

    lsb_release -aip

    如,个人系统显示:get

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trustyit

    显示了一些ubuntu的版本信息,须要获得的是Codename,好比,我这里是trustyio

2. 确认阿里源支持:

    登录如下网页:http://mirrors.aliyun.com/ubuntu/dists/

    该网页显示了阿里云支持的ubuntu系统下各个Codename版本,确保本身的Codename在该网页中存在(通常都会有的)

2. 备份系统源:

    cd /etc/apt
    sudo mv sources.list sources.list_bak

3. 添加新的源文件:

    sudo vi sources.list

并添加如下内容:注意,每一行的trusty应该用第一步查看获得的Codename来代替

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

4. 保存而且sudo apt-get update,更新成功

5. 如下提供配置脚本:

复制代码
 1 Codename=$( (lsb_release -a)|awk '{print $2}'|tail -n 1 )
 2 echo "\
 3 deb http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
 4 deb http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
 5 deb http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
 6 deb http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
 7 deb http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe
 8 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
 9 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
10 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
11 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
12 deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe ">sources.list
13 apt-get update
复制代码

sudo运行该脚本便可(注意运行以前最好备份以前的sources.list)

相关文章
相关标签/搜索