Skip to main content

Ubuntu 18.04 apt 改为阿里云源

仅作记录,Ubuntu 不管是系统还是docker镜像都比较常用。但是 ubuntu docker 没有 vim,更新国内源不方便。很多时候都要用 volume 把源映射进去,非常麻烦。

先检查Ubuntu阿里云源有没有炸

❐ 点我看一看阿里云源是否正常访问,如果不能访问请留言通知我

阿里云源 sources.list

deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

有 vim

直接 vim 复制粘贴即可

有 wget 或者 curl

本站提供的 sources.list 文件下载,可用 wget 下载。

❐ 稍微看看本站的 sources.list

也可以自己部署到 github 或者 gitee gitlab,一类的托管网站,然后自己下载。

wget https://luo3.org.cn/files/ubuntu1804-aliyun.sources.list

我的系统什么都没有,只能 echo

可能我不是很会 nano,不过 docker 镜像为了精简,有时候切掉了紧急运维工具。

可以用 echo 逐行写入

echo 版
echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse' >> /etc/apt/sources.list
echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse' >> /etc/apt/sources.list

Dockerfile 版

可以用 Dockerfile 构建出集成阿里云源的镜像,就不用每次创建容器都要改源了。

用法:

docker build -t ubuntu:18.04-aliyun -f <Dockerfile文件位置> /tmp
Dockerfile
FROM ubuntu:18.04

RUN	mv /etc/apt/sources.list /etc/apt/sources.list.old \
      && echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse' >> /etc/apt/sources.list \
      && echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse' >> /etc/apt/sources.list \
      && echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse' >> /etc/apt/sources.list \
      && echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse' >> /etc/apt/sources.list \
      && echo 'deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse' >> /etc/apt/sources.list