Ubuntu配置apt安装源为清华源[含自动配置脚本]

Ubuntu配置apt安装源为清华源[含自动配置脚本]

一、备份原配置文件

Ubuntu 的软件源配置文件是/etc/apt/sources.list。将系统自带的该文件做个备份,以防万一。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

二、修改sources.list文件

我习惯与使用vim编辑文件,如果你没有安装可以执行命令sudo apt-get install vim安装。

清华ubuntu软件源配置帮助:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

Ubuntu配置apt安装源为清华源[含自动配置脚本]

选择你系统对应版本,下面的就是需要你添加到sources.list文件中的内容。

使用sudo vim /etc/apt/source.list打开文件,将文件原内容删除,添加在清华源获取的内容,保存。

三、更新软件列表和软件源

sudo apt-get update
sudo apt-get upgrade

四、 其他几个国内的软件源

4.1 中国科技大学软件源

中科大ubuntu软件源配置帮助: Ubuntu 源使用帮助 — USTC Mirror Help 文档

以下是 Ubuntu 20.04 参考配置内容:

# 默认注释了源码仓库,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

4.2 阿里云软件源

阿里云Ubuntu 18.04源,阿里云镜像站正在升级

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

五、脚本一键配置apt源

示例为ubuntu18.04配置清华镜像源,其他版本或者其他源,做对应替换即可。

#!/bin/bash
#更新apt源为清华源
echo "[Info] 正在备份默认apt源..."
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo "[Info] 正在替换apt源为清华apt源..."
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse > /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse >> /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse >> /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse >> /etc/apt/sources.list
echo "[Info] 正在更新源..."
apt update
echo "[Info] 正在更新软件..."
apt upgrade -y

Ubuntu配置apt安装源为清华源[含自动配置脚本]

上一篇:Linux系统安装和卸载nginx


下一篇:linux日志查看命令