Ubuntu一般我用的比较多,而Debian是很多docker
镜像的基础镜像,因此只记录一下这两个怎么换源。
备份原来的文件
首先我们把原来的sources.list
备份一下,这样就算换源失败也不会没法抢救了。
1 2 |
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak |
根据系统版本添加不同的源
Ubuntu16.04的版本号叫xenial
,Ubuntu18.04叫bionic
,不同的版本不可以混用哦。这里有个不同版本的版本名:
1 2 3 4 5 6 |
12.04(LTS) Precise Pangolin(精准的穿山甲) 14.04(LTS) Trusty Tahr (可靠的塔尔羊) 16.04(LTS) Xenial Xerus (好客的非洲地松鼠) 18.04(LTS) Bionic Beaver(仿生海狸) 20.04(LTS) Focal Fossa(专注的马达加斯加长尾狸猫) |
新建一个新的sources.list
:
1 2 3 |
# !-bash sudo vim /etc/apt/sources.list |
根据自己的系统版本号添加不同的源:
Ubuntu16.04
(阿里源)
1 2 3 4 5 6 7 8 9 10 11 |
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-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports 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-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse |
Ubuntu18.04
(阿里源)
1 2 3 4 5 6 7 8 9 10 11 |
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb 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 main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed 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 9 10 11 |
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 |
Debian
1 2 3 4 |
deb http://ftp.cn.debian.org/debian/ stretch main deb http://ftp.cn.debian.org/debian/ stretch-updates main deb http://ftp.cn.debian.org/debian-security stretch/updates main |
如果docker里没有vim
的话可以用echo
命令:
1 2 3 4 |
echo "deb http://ftp.cn.debian.org/debian/ stretch main" > /etc/apt/sources.list echo "deb http://ftp.cn.debian.org/debian/ stretch-updates main" >> /etc/apt/sources.list echo "deb http://ftp.cn.debian.org/debian-security stretch/updates main" >> /etc/apt/sources.list |
更新源
1 2 |
sudo apt update |
更新好以后就可以sudo apt install 包名
来安装软件了。