服务器设置和教程 · 8 10 月, 2024

Ubuntu 18.04 更改 apt 為阿里雲軟件源

Ubuntu 18.04 更改 apt 為阿里雲軟件源

在使用 Ubuntu 18.04 的過程中,默認的軟件源可能會因為地理位置或網絡速度的原因而導致更新和安裝軟件的速度變慢。為了提高這些操作的效率,許多用戶選擇將默認的 apt 軟件源更改為更快的鏡像源,例如阿里雲的軟件源。本文將詳細介紹如何在 Ubuntu 18.04 中更改 apt 軟件源為阿里雲的鏡像源。

為什麼選擇阿里雲軟件源?

阿里雲提供的軟件源在中國大陸及香港地區的訪問速度相對較快,這對於需要頻繁更新或安裝軟件的用戶來說,能夠顯著提高效率。此外,阿里雲的鏡像源通常會保持最新的軟件包,這對於保持系統的安全性和穩定性至關重要。

更改 apt 軟件源的步驟

步驟 1: 備份原有的源列表

在進行任何更改之前,建議先備份原有的源列表,以防需要恢復。可以使用以下命令來備份原有的源列表:

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

步驟 2: 編輯源列表

接下來,使用文本編輯器打開源列表文件。這裡以 nano 為例:

sudo nano /etc/apt/sources.list

在文件中,您會看到類似以下的內容:

deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
deb http://archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse

將這些行替換為阿里雲的鏡像源,以下是阿里雲的源列表:

deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

完成後,按 Ctrl + X,然後按 Y 保存更改並退出。

步驟 3: 更新 apt 包索引

更改源列表後,您需要更新 apt 包索引,以便系統能夠識別新的軟件源。使用以下命令進行更新:

sudo apt update

步驟 4: 安裝或更新軟件

現在,您可以使用 apt 安裝或更新軟件,速度應該會有所提升。例如,您可以使用以下命令安裝某個軟件包:

sudo apt install 

總結

通過將 Ubuntu 18.04 的 apt 軟件源更改為阿里雲的鏡像源,您可以顯著提高系統更新和軟件安裝的速度。這對於需要經常進行系統維護的用戶來說,無疑是一個有效的解決方案。如果您正在尋找高效的 VPS 解決方案,Server.HK 提供多種選擇,適合不同需求的用戶。無論是 香港VPS 還是其他類型的 云服务器,都能滿足您的需求。