Ubuntu 22.04/24.04 LTS 用 sed 快速換國內源
Ubuntu 配置國內源
- 首先了解下
/etc/apt/sources.list文件/etc/apt/sources.list是一個普通可編輯的文本文件,保存了ubuntu軟件更新的源服務器的地址。/etc/apt/sources.list.d/*.list該文件夾下的文件是第三方軟件的源,可以分別存放不同的第三源地址,只需“擴展名”為list即可。
配置步驟如下:
時間:2024-10
請注意:選擇和系統對應的版本,使用 lsb_release -a 查看系統版本
-
1.Ubuntu配置文件位置:/etc/apt/sources.list
-
2.需用root權限進入:sudo vim /etc/apt/sources.list
有2種修改方式
- 1.sed 把原文件中:archive.ubuntu.com,替換為:mirrors.aliyun.com(或其他服務器列表源網址)
- 2.直接復制下方對應版本的內容,覆蓋原文件中的內容即可。
修改完成后,更新本地安裝包數據庫
方式一
以 Ubuntu 22.04.5 LTS 為例
服務器列表
可將 http://cn.archive.ubuntu.com/ubuntu/ 替換為下列任意服務器 :
# Ubuntu 官方(歐洲,國內較慢,無同步延遲)
http://archive.ubuntu.com/ubuntu/
# Ubuntu 官方中國(目前是阿里云)
http://cn.archive.ubuntu.com/ubuntu/
# 網易(廣東廣州電信/聯通千兆雙線接入)
http://mirrors.163.com/ubuntu/
# 搜狐(山東聯通千兆接入)
http://mirrors.sohu.com/ubuntu/
# 阿里云(北京萬網/浙江杭州阿里云服務器雙線接入)
http://mirrors.aliyun.com/ubuntu/
# 騰訊
http://mirrors.cloud.tencent.com/ubuntu/
# 華為
http://mirrors.huaweicloud.com/ubuntu/
# 清華
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
root@ubuntu2204:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
root@ubuntu2204:~# sed -i_bak 's/cn.archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list # 更換阿里源
或
root@ubuntu2204:~# sed -i_bak 's/cn.archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list # 更換清華源
root@ubuntu2204:~# apt update
root@ubuntu2204:~# apt upgrade -y
方式二
以下內容的具體含義如下:
1)每一行的開頭是deb或者deb-src,分別表示直接通過.deb文件進行安裝和通過源文件的方式進行安裝。
2)deb或者deb-src字段之后,是一段URL,之后是五個用空格隔開的字符串,分別對應相應的目錄結構。
- ubuntu 22.04 LTS (jammy)
# 阿里源
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
# 清華源
# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# 以下安全更新軟件源包含了官方源與鏡像站配置,如有需要可自行修改注釋切換
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
- ubuntu 24.04 (noble)
# 阿里源
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
# 清華源
# 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# 以下安全更新軟件源包含了官方源與鏡像站配置,如有需要可自行修改注釋切換
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# 預發布軟件源,不建議啟用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
********** 如果您認為這篇文章還不錯或者有所收獲,請點擊右下角的【推薦】/【贊助】按鈕,因為您的支持是我繼續創作分享的最大動力! **********
作者:講文張字
出處:http://www.rzrgm.cn/zhangwencheng
版權:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出 原文鏈接
出處:http://www.rzrgm.cn/zhangwencheng
版權:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出 原文鏈接
浙公網安備 33010602011771號