Ubuntu 换源 看着一篇就够了

Ubuntu 换源 看着一篇就够了

换源
ubuntu的源存放在/etc/apt/source.list,在换源之前我们要记得对之前的源进行备份,这样的好处是,万一你不行,你还可以复原回去。

具体操作
git clone https://gitee.com/taoge2021/env-config.git

cd env-config/linux/ubuntu/sources

chmod u+x change-sources.sh

./change-sources.sh
如果遇到运行./change-sources.sh脚本权限不足的问题,尝试可以用
chmod 777 change-sources.sh命令更改权限
或者使用root用户来运行change-sources.sh脚本

脚本
ubuntu有很多个版本,12.04之前的我们就不管它了,太老了。每一个版本都有一个代号,比如trusty(14.04)、xenial(16.04)、bionic(18.04)、groovy(20.10)、hirsute(21.04)。不管代号怎么变,相关的源的网址它是固定的,比如五道口的源是https://mirrors.tuna.tsinghua.edu.cn/ubuntu, 阿里的源是http://mirrors.aliyun.com/ubuntu。所以,我们其实可以写个脚本去做这件事,输入是ubuntu的版本号,输出是相关的源(这里选五道口和阿里的吧)。

脚本如下:

#!/bin/bash

function change_sources() {
echo “#======= change sources.list start =======#”
echo “Input Your Ubuntu Version:”
read UBUNTU_VERSION
echo “Your Ubuntu Version is ${UBUNTU_VERSION}”
if [ ${UBUNTU_VERSION} = “12.04” ] || [ ${UBUNTU_VERSION} = “14.04” ] || [ ${UBUNTU_VERSION} = “16.04” ] || [ ${UBUNTU_VERSION} = “18.04” ] || [ ${UBUNTU_VERSION} = “20.10” ] || [ ${UBUNTU_VERSION} = “21.04” ]; then
cp /etc/apt/sources.list /etc/apt/sources.list.bak
cp ./apt/${UBUNTU_VERSION}/sources.list /etc/apt/sources.list
apt-get update && apt-get upgrade
fi
echo ‘#======= change sources.list end =======#’
}

change_sources

20.10 版本的源
20.04的ubuntu经测试也可以用,将/etc/apt/source.list的内容替换即可。

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-backports main restricted universe multiverse

# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ groovy-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ groovy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ groovy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ groovy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ groovy-backports main restricted universe multiverse

# deb-src http://mirrors.aliyun.com/ubuntu/ groovy main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ groovy-security main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ groovy-updates main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ groovy-backports main restricted universe multiverse

# deb http://mirrors.aliyun.com/ubuntu/ groovy-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ groovy-proposed main restricted universe multiverse

    THE END
    喜欢就支持一下吧
    点赞11 分享
    评论 抢沙发
    头像
    欢迎您留下宝贵的见解!
    提交
    头像

    昵称

    取消
    昵称表情代码图片

      暂无评论内容