I want to update my sources.list file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn't seem to be a simple way to do it from from the command line?
There are two different working answers to this question below:
- Use apt-get's
mirror:method
This method asks the Ubuntu server for a list of mirrors near you based on your IP, and selects one of them. The easiest alternative, with the minor downside that sometimes the closest mirror may not be the fastest.- Command-line foo using netselect
Shows you how to use the netselect tool to find the fastest recently updated servers from you -- network-wise, not geographically. Usesedto replace mirrors insources.list.
The other answers, including the accepted answer, are no longer valid (for Ubuntu 11.04 and newer) because they recommended Debian packages such as
netselect-aptandapt-spywhich do not work with Ubuntu.
Use sed to replace mirrors in sources.list
Since some sources use addition folders as part of their path it might be better to use the alternate separator syntax.
sudo sed -i 's%us.archive.ubuntu.com%mirrors.gigenet.com/ubuntuarchive/%' /etc/apt/sources.list
#signs with slashes (/). Otherwise I gotsed: -e expression #1, char 53: unterminateds' command`. – Ethan Leroy Oct 18 '13 at 21:18