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

I have a Lucid Server (10.04) set up and I would like to change the mirror from US (or any other country) to the Main Ubuntu Mirror.

For example my two first entries in sources.list are:

deb lucid main restricted
deb-src lucid main restricted

In a Desktop environment I would select the main mirror like this:

Software Sources

But how do I do that from the terminal as I don't have a graphical environment installed!

4 Answers

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

sudo nano /etc/apt/sources.list

Locate the text and replace it with .

8

This command should do the trick:

sudo sed -i 's| /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 . with http:// in the file /etc/apt/sources.list.

4

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

With vim:

mv /etc/apt/sources.list{,.bak} # you may want to make a backup
vim /etc/apt/source.list

Type : (you need to hold Shift) to enter command-ine mode, and then type:

%s/http:\/\/us\./http:\/\//g

Hit Enter

Hit Esc to be sure you've exited the command-line mode and entered normal mode. Now you can scroll around the file with keyboard move keys (if you want) to make sure all occurrences of us mirrors have been edited.

Finally, exit with saving by entering command-line mode (type :) and enter wq! to save and exit vim.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like