简介

Linux、类Linux系统都是用叫做 Package Manager 用来管理软件包的,这里我以Ubuntu 18.04为例介绍一下如何使用命令来安装软件包

1
apt install pk-name

随便安装一个软件包,会发现速度不是很慢就是根本连接失败,那难道就没有别的办法了吗?


修改

其实,我们可以对系统进行切换源操作,图形界面的Ubuntu在设置里会自带切换源的方式,不过命令行就需要手动切换了👇

系统里有一个文件用来专门处理软件源的,我们首先复制该文件,命令如下👇

1
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

接下来我们使用文本编辑器将其修改,这里推荐使用nano编辑器,可以通过apt install nano来安装,如果因为网络安装不了,也可以使用自带的vim

删除原来的所有内容,将以下内容选择一个复制进去:

⚠警告:下列软件源只适用于 Ubuntu 18.04,如因为版本使用错误等问题本人概不负责,可以自行尝试使用.bak还原

阿里源

1
2
3
4
5
6
7
8
9
10
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源

1
2
3
4
5
6
7
8
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

编辑好后保存退出,使用

1
sudo apt update

来更新软件源,这样就替换好啦