Ubuntu 22.04/24.04 LTS 用 sed 快速換國內源

讲文张字發表於2024-10-18

Ubuntu 配置國內源

配置步驟如下:

時間: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,替換為:archive.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

方式二

  • 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

相關文章