ubuntu/docker内切换 阿里云软件源
此文章适用于ubuntu系统和docker,因为docker内置系统也是ubuntu
1、备份原有源配置文件
镜像源文件在/etc/apt/sources.list
#先创建一个放备份文件的地方,方便发生错误后还原
mkdir /mnt/vdba/backup
mv /etc/apt/sources.list apt-sources-list.ba
2、切换源之前需要先安装一个gpg
因为我是在docker中做的源切换,当换了镜像源后执行apt-get update发现报错 提示我no_pubkey,镜像地址的公钥没有加进去,所以需要加进去,但是添加密钥的时候有提示我如下错误
gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation
查找解决方案,发现需要先安装gnupg2
#安装gnupg2
apt-get update && apt-get install -y gnupg2
有的地方网不好,会比较慢。。。。。。这也是我为什么要换镜像源的原因
安装成功后切换源
3、在/etc/apt下编辑sources.list
cat << EOF > /etc/apt/sources.list
#复制如下内容
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 multiverse12345678910
EOF
#回车结束
编辑完成后执行更新命令
#安装公钥
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 9D6D8F6BC857C906
apt-get update
apt update
贼快!!!!