Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 46 down vote accepted

Open your source.list using your favorite text editor, ie

sudo nano /etc/apt/sources.list

locate and replace it with

share|improve this answer
I've figured this would do the trick but when I did as you suggested but it gave me a 404 error for the repository. I've checked again now and it seems to be okay. It seemed to be a problem with my network connection. Thank you very much for the answer. – Sorin-Mihai Oprea Feb 16 '12 at 11:10
is there a secure way like with the GUI. I mean, not replacing it manually and avoiding typos or whatever. – logoff Jan 10 '14 at 11:24
Maybe something like this:… @logoff – Luke Stanley Feb 28 '14 at 0:39

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.

  • The forward slash is the delimiter between the command and arguments except where it is escaped with a backslash.

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

Note: if your replacement text has forward slashes, it may be clearer to use a pipe as the sed delimiter (ref, e.g.:

sudo sed -i 's|http://us.|http://|g' /etc/apt/sources.list
share|improve this answer
Try explaining the command a little more, what does it do? – Evandro Silva Dec 10 '14 at 13:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.