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)

时间: 2024-10-17 19:35:35

ubuntu更换阿里源的相关文章

ubuntu更换apt-get源&apt命令使用手册

ubuntu更换apt-get源 # cp /etc/apt/sources.list /etc/apt/sources.list.bak # vim /etc/apt/sources.list deb http://mirrors.163.com/ubuntu/ precise main restricted deb-src http://mirrors.163.com/ubuntu/ precise main restricted deb http://mirrors.163.com/ubu

docker ubuntu容器更换阿里源(转)

问题:使用docker 利用下载的ubuntu镜像启动容器时,使用的源下载更新软件的速度较慢. 解决这个问题的方法是跟新ubuntu容器的源 示例:以ubuntu为基础镜像 启动一个名称为 test02的容器,并且开启shell交互(/bin/bash ) docker run -ti --name test02 ubuntu /bin/bash 用自带vi修改源 [email protected]:/# vi /etc/apt/sources.list 将原有内容删除,并替换为以下的阿里源 d

Ubuntu17.04更换阿里源

命令:sudo vim /etc/apt/sources.list 阿里源: deb http://mirrors.aliyun.com/ubuntu/ zesty main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ zesty-backports main multiverse restricted universe deb http://mirrors.aliyun.com/ubuntu/ zes

Ubuntu更换科大源

更换科大源 方案一:在命令行输入 sudo gedit /etc/apt/sources.list ,打开系统自带源文件. 将文件内源删除,更换为以下科大源: deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

centos 7更换阿里源

转自 https://blog.csdn.net/jameshadoop/article/details/54881295 centos7 修改yum源为阿里源,某下网络下速度比较快 首先是到yum源设置文件夹里 1.安装base reop源 cd /etc/yum.repos.d1接着备份旧的配置文件 sudo mv CentOS-Base.repo CentOS-Base.repo.bak1下载阿里源的文件 sudo wget -O CentOS-Base.repo http://mirro

Ubuntu——切换阿里源

前言 Windows配套更新~ 步骤 更新之前不要忘记先备份,然后删除现有的直接粘贴最终结果即可 [email protected]:~# cd /etc/apt/ [email protected]:/etc/apt# cp -rvf sources.list sources.list.back 阿里源 原文地址:https://www.cnblogs.com/wangyang0210/p/12602281.html

ubuntu 更换阿里云的源

首先备份本地的源 cp /etc/apt/sources.list /etc/apt/sources.list.bak 编辑源文件 vim /etc/apt/sources.list 删除原有内容,添加下面内容 deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main rest

Ubuntu 18.04 更换阿里源

1.备份 sudo cp /etc/apt/source.list /etc/apa/source.list.bak 2.编辑 sudo vim /etc/apt/source.list 3.修改内容 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted uni

Ubuntu更换软件源

在系统中/etc/apt/source.list 中为软件源 国内源有: ###中科大源 deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn