在Linux中更换软件源,通常是编辑 /etc/apt/sources.list
文件或者在 /etc/apt/sources.list.d/
目录下的相关.list
文件。以下是更换为阿里云源的例子:
1.备份原有的 sources.list
文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2.编辑 sources.list
文件:
sudo nano /etc/apt/sources.list
3.将文件中的内容替换为阿里云源(以Ubuntu为例):
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-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-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports 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-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
4.保存文件并退出编辑器。
5.更新软件源:
sudo apt update
请根据您使用的Linux发行版和版本,从对应的软件源提供商那里获取正确的源地址。上述例子中的 bionic
是Ubuntu 18.04的代号,如果您使用的是其他版本,请替换为相应的代号,例如 focal
对应Ubuntu 20.04。