目录
x-cmd 一键配置apt和yum源
x-cmd是一个Linux工具套箱,很多功能开箱即用,可以非常方便的切换各种国内常用源,非常推荐。
x-cmd官网为:x-cmd
一键安装x-cmd
eval "$(curl https://get.x-cmd.com)"
设置 Ubuntu apt 源
x-cmd 查询Ubuntu apt源
x apt mirror ls
x-cmd 设置Ubuntu apt源设置为阿里源
x apt mirror set ali
x-cmd 删除之前的设置
x mirror apt unset
设置 CentOS yum源
x-cmd 查询CentOS yum源
x yum mirror ls
x-cmd 设置CentOS yum源为ali源
x yum mirror set ali
x-cmd 删除之前CentOS yum源设置
x yum mirror unset
手动配置Linux国内可用源
Ubuntu 22.04
Ubuntu 的apt update可能会因为当前 设备时间不对应,导致证书过期。因此执行update之前最好是先将时间同步为现实时间。
阿里源
deb https://mirrors.aliyun.com//ubuntu jammy main restricted
deb https://mirrors.aliyun.com//ubuntu jammy-updates main restricted
deb https://mirrors.aliyun.com//ubuntu jammy universe
deb https://mirrors.aliyun.com//ubuntu jammy-updates universe
deb https://mirrors.aliyun.com//ubuntu jammy multiverse
deb https://mirrors.aliyun.com//ubuntu jammy-updates multiverse
deb https://mirrors.aliyun.com//ubuntu jammy-backports main restricted universe multiverse
deb https://mirrors.aliyun.com//ubuntu jammy-security main restricted
deb https://mirrors.aliyun.com//ubuntu jammy-security universe
deb https://mirrors.aliyun.com//ubuntu jammy-security multiverse
163源
deb http://mirrors.163.com/ubuntu jammy main restricted
deb http://mirrors.163.com/ubuntu jammy-updates main restricted
deb http://mirrors.163.com/ubuntu jammy universe
deb http://mirrors.163.com/ubuntu jammy-updates universe
deb http://mirrors.163.com/ubuntu jammy multiverse
deb http://mirrors.163.com/ubuntu jammy-updates multiverse
deb http://mirrors.163.com/ubuntu jammy-backports main restricted universe multiverse
deb http://mirrors.163.com/ubuntu jammy-security main restricted
deb http://mirrors.163.com/ubuntu jammy-security universe
deb http://mirrors.163.com/ubuntu jammy-security multiverse
官方源
deb http://archive.ubuntu.com/ubuntu jammy main restricted
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted
deb http://archive.ubuntu.com/ubuntu jammy universe
deb http://archive.ubuntu.com/ubuntu jammy-updates universe
deb http://archive.ubuntu.com/ubuntu jammy multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
deb http://archive.ubuntu.com/ubuntu jammy-security universe
deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
使用方法
-
替换配置文件
- 备份原有源列表:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
- 编辑源列表:
sudo nano /etc/apt/sources.list
- 将内容替换为阿里源或163源。
- 备份原有源列表:
-
更新源
- 更新软件包列表:
sudo apt-get update
- 升级已安装的软件包:
sudo apt-get upgrade
- 更新软件包列表:
CentOS 7.1
阿里源
- 备份原有源:
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 下载阿里源:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- 清理缓存并生成新缓存:
sudo yum clean all sudo yum makecache
163源
不知为何现在无法拉到163源,此处可用性存疑
- 备份原有源:
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 下载163源:
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
- 清理缓存并生成新缓存:
sudo yum clean all sudo yum makecache