Ubuntu系统更换软件源地址详细教程

Ubuntu 包管理器 apt 默认使用官方仓库,速度比较慢。本文讲解如何设置为国内仓库镜像。

文章目录(展开/隐藏→)

展开
4.7
(3)

Ubuntu的默认包管理器是 apt ,apt 从如下文件中获取软件库地址,如下图。

可以看出 Ubuntu 默认使用官方仓库的地址,在国内使用官方仓库的访问速度比较慢,有时候下载也会失败。

因为国内仓库一般比官方仓库要快,所以一般在系统安装好后都会更换为国内仓库。下面说明如何更换源地址为国内源地址。

Ubuntu系统更换软件源地址详细教程

注意,国内不同地方的因为网络差异各仓库速度会不同,所以建议先测试仓库速度再更换为速度最快的。

Ubuntu系统更换软件源地址详细教程

手动修改 Ubuntu 源地址(Ubuntu 22.04)

Ubuntu 22.04 的原始 sources.list 内容如下

#deb cdrom:[Ubuntu 22.04 LTS _Jammy Jellyfish_ - Release amd64 (20220419)]/ jammy main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu jammy-security main restricted # deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted deb http://security.ubuntu.com/ubuntu jammy-security universe # deb-src http://security.ubuntu.com/ubuntu jammy-security universe deb http://security.ubuntu.com/ubuntu jammy-security multiverse # deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse # This system was installed using small removable media # (e.g. netinst, live or single CD). The matching "deb cdrom" # entries were disabled at the end of the installation process. # For information about how to configure apt package sources, # see the sources.list(5) manual.

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 
# newer versions of the distribution. 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the 
## distribution. 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team. Also, please note that software in universe WILL NOT receive any 
## review or updates from the Ubuntu security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu 
## security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as 
## extensively as that contained in the main release, although it includes 
## newer versions of some applications which may provide useful features. 
## Also, please note that software in backports WILL NOT receive any review 
## or updates from the Ubuntu security team. 
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse 
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted 
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted 
deb http://security.ubuntu.com/ubuntu jammy-security universe 
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe 
deb http://security.ubuntu.com/ubuntu jammy-security multiverse 
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media 
# (e.g. netinst, live or single CD). The matching "deb cdrom" 
# entries were disabled at the end of the installation process. 
# For information about how to configure apt package sources, 
# see the sources.list(5) manual.
Ubuntu系统更换软件源地址详细教程

首先备份 sources.list

因为接下来要修改 sources.list 文件 ,有必要先备份一下。如果修改错了可以方便找回来。

# 进入 apt 目录 
cd /etc/apt 
# 备份 sources.list 文件 
sudo cp sources.list sources.list.backup
Ubuntu系统更换软件源地址详细教程

更换镜像地址

可以使用原始 sources.list 文件,把 URL 换成 ,需要的镜像地址即可。这里替换 sources.list 文件中,所有的 cn.archive.ubuntu 为 mirrors.aliyun(使用阿里云镜像)

2.1 使用 vim 打开 sources.list 文件

# 使用 vim 打开 
sudo vim sources.list

# 如果没有安装 vim 使用下面命令安装 
sudo apt install vim

使用 vim 编辑器,打开后键盘使用快捷键 “ Ctrl + : ” ,输入如下命令 ,注意只需要执行下面,任意一个命令就行了。这里需要注意的是,冒号是vim的指令语句。所以,以下带冒号的语句,需要先输入冒号,再输入后续命令。

# 替换成阿里镜像 
:%s/cn.archive.ubuntu/mirrors.aliyun/g

# 替换成中科大镜像 
:%s/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g
Ubuntu系统更换软件源地址详细教程

然后再替换所有 security.ubuntu ,令 ,注意只需要执行下面,任意一个命令就行了。

# 替换成阿里镜像 
:%s/security.ubuntu/mirrors.aliyun/g

# 替换成中科大镜像 
:%s/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g
Ubuntu系统更换软件源地址详细教程

2.2使用 vim 命令 :wq 保存

Ubuntu系统更换软件源地址详细教程

2.3最后结果如下

#deb cdrom:[Ubuntu 22.04 LTS _Jammy Jellyfish_ - Release amd64 (20220419)]/ jammy main restricted # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse # deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu jammy-security main restricted # deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted deb http://security.ubuntu.com/ubuntu jammy-security universe # deb-src http://security.ubuntu.com/ubuntu jammy-security universe deb http://security.ubuntu.com/ubuntu jammy-security multiverse # deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse # This system was installed using small removable media # (e.g. netinst, live or single CD). The matching "deb cdrom" # entries were disabled at the end of the installation process. # For information about how to configure apt package sources, # see the sources.list(5) manual.

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 
# newer versions of the distribution. 
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the 
## distribution. 
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team. Also, please note that software in universe WILL NOT receive any 
## review or updates from the Ubuntu security team. 
deb http://mirrors.aliyun.com/ubuntu/ jammy universe 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy universe 
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu 
## security team. 
deb http://mirrors.aliyun.com/ubuntu/ jammy multiverse 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy multiverse 
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as 
## extensively as that contained in the main release, although it includes 
## newer versions of some applications which may provide useful features. 
## Also, please note that software in backports WILL NOT receive any review 
## or updates from the Ubuntu security team. 
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse 
# deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

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

# This system was installed using small removable media 
# (e.g. netinst, live or single CD). The matching "deb cdrom" 
# entries were disabled at the end of the installation process. 
# For information about how to configure apt package sources, 
# see the sources.list(5) manual.

最后执行 apt 更新命令

apt update (apt-get(8)) update is used to download package information from all configured sources. 
Other commands operate on this data to e.g. perform package upgrades or search in and display details about all packages available for installation.
sudo apt update
Ubuntu系统更换软件源地址详细教程

共计3人评分,平均4.7

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

本文投稿作者:飒飒,如若转载,请注明出处:https://iymark.com/computer/linux/ubuntu-change-sourceaddress.html

(0)
上一篇 2022年09月19日 19:46
下一篇 2022年09月19日 21:59

相关推荐

发表回复

登录后才能评论
本站APP