ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

更换Ubuntu源为国内源的操作记录

2021-04-11 12:52:33  阅读:217  来源: 互联网

标签:http 源为 更换 Ubuntu xenial ubuntu deb main com


 

我们都知道,Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源(比如阿里源),这样用起来就很快了。下面记录下更换操作:

首先了解下/etc/apt/sources.list文件
文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址。
和sources.list功能一样的是/etc/apt/sources.list.d/*.list(*代表一个文件名,只能由字母、数字、下划线、英文句号组成),
该文件夹下的文件是第三方软件的源,可以分别存放不同的第三源地址,只需“扩展名”为list即可。
sources.list.d目录下的*.list文件为在单独文件中写入源的地址提供了一种方式,通常用来安装第三方的软件。

如下是ubuntu官方sources.list文件内容:
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

以上内容的具体含义如下:
1)每一行的开头是deb或者deb-src,分别表示直接通过.deb文件进行安装和通过源文件的方式进行安装。
2)deb或者deb-src字段之后,是一段URL,之后是五个用空格隔开的字符串,分别对应相应的目录结构。
在浏览器中输入http://archive.ubuntu.com/ubuntu/,并进入dists目录,可以发现有5个目录和前述sources.list文件中的第三列字段相对应。
任选其中一个目录进入,可以看到和sources.list后四列相对应的目录结构


以上官方的ubuntu源在国内使用,通常都会很慢,以至于在使用过程中报错。
----------------下面是我在线上使用过的一个ubuntu的源---------------------
root@ubuntutest03-KVM:~# cat /etc/apt/sources.list|grep -v "^#"|grep -v "^$"
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse

--------------下面是替换成阿里源的内容-------------
root@ubuntutest03-KVM:~# cat /etc/apt/sources.list
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-backports main restricted universe multiverse  
##测试版源  
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed 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-backports main restricted universe multiverse  
##测试版源  
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse  
# Canonical 合作伙伴和附加  
deb http://archive.canonical.com/ubuntu/ xenial partner  
deb http://extras.ubuntu.com/ubuntu/ xenial main

root@ubuntutest03-KVM:~# apt-get update 更新源  
root@ubuntutest03-KVM:~# apt-get upgrade 更新软件 


-------------更换成其他开放的ubuntu源,做法和上面同理----------------
再比如下面更换成网易源(打开文件中的url。进入dists目录下就能看到xenial等对应的目录结构了)
root@ubuntutest03-KVM:~# cat /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ xenial main restricted
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted
deb http://mirrors.163.com/ubuntu/ xenial universe
deb http://mirrors.163.com/ubuntu/ xenial-updates universe
deb http://mirrors.163.com/ubuntu/ xenial multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse

root@ubuntutest03-KVM:~# apt-get update 更新源  
root@ubuntutest03-KVM:~# apt-get upgrade 更新软件

标签:http,源为,更换,Ubuntu,xenial,ubuntu,deb,main,com
来源: https://blog.51cto.com/u_10272167/2698818

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有