ubuntu 更换阿里源实例

网上应该可以找到很多关于ubuntu源的设置方法,但是如果不搞清楚就随便设置的话,不仅不能起到应有的效果,还会由于一些问题导致apt不可用。

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

## 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.tmpl

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

以下提供设置阿里源的方法,其他源也可以如法炮制:

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

lsb_release -a

如,我的系统显示:

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

显示了一些ubuntu的版本信息,需要得到的是Codename,比如,我这里是trusty

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 http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe

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)

(0)

相关推荐

  • Openstack使用ubuntu镜像启动虚拟机实例详解

    一般情况下OpenStack环境搭建好了之后,就是测试启动虚拟机.通常我们会使用一个最基本的镜像cirros-0.3.3-x86_64-disk.img来作为镜像,使用glance命令行或者horiz ...

  • 如何更换阿里云网站域名和空间?

    本文将教你如何更换现有网站的域名和空间,让你实现网站搬家功能,不用改动网站的原来信息. 操作方法 01 1.登陆阿里云平台,点击左上角"登陆"按钮,成功登陆后,点击"管理 ...

  • 使用apt-mirror搭建Ubuntu软件源的实例教程

    搭建自有Ubuntu源的原因有很多 节省外网带宽提前下载,缓解国外源下载缓慢私有定制软件包发布 本文测试环境 ubuntu 14.04(LTS) 64位apt-mirror 版本 0.5.1-1ngi ...

  • Ubuntu 10.04 更新源大全(国内)

    Ubuntu 10.04 更新源大全(国内)

  • 用国内软件源为Ubuntu的apt-get提速方法

    默认的,apt-get会连接http://us.archive.ubuntu.com/,看域名就知道这是一个美国的服务器。身处我们伟大的中华局域网中连美国的服务器当然很慢了。 这个软件源可以通过/et ...

  • ubuntu软件源 sudo apt-get update更新列表

    复制代码 代码如下: #电子科技大学</p><p>deb http://ubuntu.uestc.edu.cn/ubuntu/ quantal main restricted ...

  • Ubuntu怎么修改apt-get更新源?

    手动修改Ubuntu的apt-get源 1.用ssh工具连接到Ubuntu(我用的xshell) 2.命令行敲入 cd /etc/apt/ 3.备份此目录下的source.list文件(要有sudo权 ...

  • ubuntu系统怎么使用阿里云服务器?

    ubuntu里怎样使用阿里云服务器?下面我们就来看看详细的教程. 1.打开UBUNTU操作系统. 2.找到左下角的图标,并且进行单击. 3.这里弹出很多图标可以选择.我们可以在下方找到软件更新. 4. ...

  • 阿里云服务器配置与性能优化

    阿里云我问过很多站长都说非常的不错了,不管是网速还是从性能都比其它主机要好,但阿里云就是贵那么一点了,下面小编来给各位介绍阿里云服务器配置与性能优化 更换阿里云服务器有一阵了,相对于我以前的虚拟主机不 ...