Ubuntu16.04 replace software source

For the Ubuntu system, the sources of different versions are different, and each version has its own dedicated source. And for the same distribution of Ubuntu, its sources are distributed on servers all over the world. The official source server used by Ubuntu by default is in Europe, and the access speed from China is very slow. Ali, NetEase and some key universities in China also have Ubuntu sources, so after installing the Ubuntu system, it is best to replace the official sources with domestic sources.
step 1: First look at what sources are available in China, click me to view
Select Alibaba Cloud Source or Tsinghua University Source (of course other sources are fine), and copy the server address of their Ubuntu source first, which will be used below.
Alibaba Cloud Source: http://mirrors.aliyun.com/ubuntu/
Tsinghuayuan: http://mirrors.tuna.tsinghua.edu.cn/ubuntu/

step 2: Get your own Ubuntu codename
Each distribution of Ubuntu has its own code name. We need to find the corresponding source through the code name of Ubuntu on our computer, Ctrl+Alt+T to open the terminal, and execute the following command:

lsb_release -a

Then we will get the version information of our own Ubuntu, and the last column of codename is the codename of our own Ubuntu. For example, I installed Ubuntu 16.04.7, and the code name found is xenial.

step 3: Edit the source
Find the template at the top of the page opened in step 1: 16.04source , copy the content into a text editor, and then copy the URL http://cn.archive.ubuntu.com/ubuntu/ Replace it with the URL you want to replace, and replace xenial with your own Ubuntu codename.

For example, I chose Alibaba Cloud Source, and the replacement is as follows:

# Alibaba Cloud Source
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##beta source
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
# source code
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
##beta source
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

step4: Backup the original source file

Open source file path:

cd /etc/apt/

Backup the source file sources.list, backup sources.list to sources.list.bak

sudo cp sources.list sources.list.bak

step5: Modify the source file

Execute the command to open the source.list file: it can be opened with tools such as vim, gedit (recommended to use gedit)

sudo gedit /etc/apt/source.list

Then copy the prepared source to source.list and overwrite the original file content

step6: update command

sudo apt-get update

If no error is reported at the end of the operation, it proves that the software source has been successfully replaced!

Unexpected: After running the sudo apt-get update command, an error was reported:

Clearsigned file isn't valid, got 'NOSPLIT' (does the network require authentication?)

Reason: No authorization to connect to the external network!

It may be the campus network or other WiFi that needs to be logged in! And the virtual machine is in bridge mode (although the machine is already connected to the network, but the virtual machine is not connected to the network), so you need to open the browser in the ubuntu of the virtual machine, enter the campus account password to log in, or change the bridge mode to for NAT mode.

Tags: Linux

Posted by vickyjackson on Mon, 09 May 2022 12:22:20 +0300