ubuntu更换阿里源实践

简介: 网上应该可以找到很多关于ubuntu源的设置方法,但是如果不搞清楚就随便设置的话,不仅不能起到应有的效果,还会由于一些问题导致apt不可用。最正确的更换源的方法应该如系统提示的:a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.

网上应该可以找到很多关于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
  1. 确认阿里源支持:

    登陆以下网页: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

  1. 保存并且sudo apt-get update,更新成功
  2. 以下提供配置脚本:
    Codename=$( (lsb_release -a)|awk '{print $2}'|tail -n 1 )

echo "\
deb http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ $Codename-updates main multiverse restricted universe ">sources.list
apt-get update

udo运行该脚本即可(注意运行之前最好备份之前的sources.list)

相关文章
|
3月前
|
Ubuntu
ubuntu 22.04 阿里源
ubuntu 22.04 阿里源
1207 0
|
5月前
|
Ubuntu
ubuntu 换源 阿里源
ubuntu 换源 阿里源
602 0
|
8月前
|
Ubuntu
Ubuntu系统镜像下载,国内镜像站大全(山大/清华/阿里/浙大/中科大...)
装Ubuntu,是很多理工科同学入门的第一个挑战,首先我们就需要找到一个能用的iso镜像,根据你的网络环境的不同,不同的站点下载速度会不一样,下面列举一下几个比较好用的,都是来自Ubuntu官方推荐镜像站链接导航国内分区
2348 0
|
5月前
|
Ubuntu PHP 开发工具
ubuntu 使用命令行更换国内源
ubuntu 使用命令行更换国内源
499 35
|
8月前
|
Ubuntu Linux
【Ubuntu系统更换清华大学镜像源【详解】】
Ubuntu是一种基于Debian的Linux操作系统,它的软件仓库中包含了许多开源软件包。由于全球用户的数量众多,因此Ubuntu的官方镜像源可能会受到访问压力的影响而变得较慢。为了避免这种情况,我们可以将Ubuntu系统的镜像源切换到清华大学镜像源。本文将详细介绍如何在Ubuntu系统中更换清华大学镜像源。
990 0
|
8月前
|
Ubuntu C语言
Ubuntu 换阿里源
先说问题,今天在配置Ubuntu按照网上找的换源办法换源之后安装gcc之后无法安装G++。
1056 0
|
9月前
|
Ubuntu 索引
ubuntu更换apt源后依然搜索旧软件源下载失败问题
ubuntu更换apt源后依然搜索旧软件源下载失败问题
432 0
|
9月前
|
Ubuntu C语言
Ubuntu下更换gcc版本
Ubuntu下更换gcc版本
373 0
|
9月前
|
Ubuntu
ubuntu16.0更改国内阿里源,速度起飞,亲测可用
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup #备份当前也就是默认官方的源列表
1506 0
|
Ubuntu
Ubuntu 更换国内源
Ubuntu 更换国内源
1633 0