How do I change mirrors in Ubuntu Server from regional to main?

Open your sources.list file using your favorite text editor, e.g.

sudo nano /etc/apt/sources.list

Locate the text http://us.archive.ubuntu.com/ubuntu and replace it with http://archive.ubuntu.com/ubuntu.


This command should do the trick:

sudo sed -i 's|http://us.|http://|g' /etc/apt/sources.list

It will remove the 'us.' prefix in each of the addresses to convert them to addresses of the main server.

Of course replace 'us' by any other mirror you are using.

In depth explanation of command:

sed - stream editor for filtering and transforming text.

  • The -i argument is to edit a file in place.

  • Then 's|regexp|replacement|g', s specifying the search and replace command.

  • The g at the end being the argument to "globally" search.

  • Conclusion: replaces all occurrences of http://us. with http:// in the file /etc/apt/sources.list.


Correct sed usage to remove/change country code "us" from source.list to something else like "au", the command will be as follows:

sed -i 's/http:\/\/us./http:\/\/au./g' /etc/apt/sources.list

or just to remove "us" alone instead of changing it to something, use code below:

sed -i 's/http:\/\/in./http:\/\//g' /etc/apt/sources.list