[TOC]

概述

备份源列表

Ubuntu缺省的配置的源并不是国内的服务器,下载更新软件都比较慢,本文介绍如何设置源列表,选择比较快的源以节省下载时间。

1
2
# 首先备份源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

sources.list文件修改

选择合适的源,替换原文件的内容,保存编辑好的文件, 以阿里云更新服务器为例(从实际测试上结果分析,个人认为阿里云比网易和搜狐的服务器要快):

1
sudo gedit /etc/apt/sources.list

阿里云镜像源-清华镜像源

注意根据具体使用的Ubuntu的版本不同,将文本中trusty替换为下面对应版本的字符串:

Ubuntu 18.04 TLS版本阿里云镜像源:

1
2
3
4
5
6
7
8
9
10
11
12
13
# https://opsx.alibaba.com/mirror
deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

# 仿照清华镜像源,注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# deb-src https://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

Ubuntu 18.04 TLS版本清华镜像源:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

刷新列表

1
2
3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential

问题解决

如果执行sudo apt-get update仍然报错,问题在于DNS没有配置好。
解决方法:

1
sudo vi /etc/resolv.conf

在其中添加:

1
2
3
4
5
6
7

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
#这里用的是阿里云的DNS服务器
nameserver 223.5.5.5
nameserver 223.6.6.6