In this guide on updating the repository mirror on Raspbian, we will be showing you how you can change the Raspbian sources list to point to a different Raspbian mirror.
There are various reasons why you might want to do this, one of these is that sometimes Raspberry Pi’s mirror director can pick a slow mirror for your connection which can significantly slow down the updating process.
Knowing how to change the Raspbian repository mirror can also help out if the Raspberry Pi’s mirror director goes offline.
The Raspbian maintainers provide a list of verified package mirrors that synchronize themselves with the central repository at least twice a day.
The list of verified package mirrors makes it easy to select one that is both safe and reliable.
As the title of this tutorial suggests, you will need to be running Raspbian, I suggest the latest version. Any other operating system and instructions for changing the repository mirror might be different.
Below are all the pieces of equipment that I made use of for this guide on changing the repository mirror.
Raspberry Pi 2 or 3
Below you can watch our video that takes you through the steps on you how to change the repository mirror on Raspbian. Very handy if you like to see things being done visually rather than text.
Alternatively, you can read our written guide underneath the video.
Can’t see the video? Please support us by disabling your adblocker.
Changing the Raspbian Repository Mirror
1. The first thing we must do to replace the Raspbian package mirror is to find one to replace it with.
To do this, we will be going to the official Raspbian website to view their list of verified Raspbian repository mirrors.
Now go to the Raspbian Mirrors website here.
2. On this website, you should see a list of Raspbian mirrors sorted by the continent and country that they are situated in as well as the organization that is providing that mirror.
Go through the list and find a mirror provider that is best suited to where you live.
You can utilize a command such as ping to see the response time from each provider however that isn’t the best indicator of how fast they will allow you to download. The best test is to download from it and compare the speed to other mirrors.
Since we are situated in the Oceania area, we will be making use of the mirror provided by AARNet.
This means the URL that we will utilize will be the one below.
3. Now that we have found a replacement Raspbian mirror we now need to go ahead and modify the sources.list file.
Let’s begin modifying this file by running the following command on the Raspberry Pi.
sudo nano /etc/apt/sources.list
4. Within this file, you will see the following text.
deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
This text defines which repository the package manager will connect to when updating.
In addition to defining the URL of the repository, it also establishes other things such as the version of the distribution that you are currently running and several other bits of information.
5. Now that we have found the correct text we need to go ahead and replace the currently defined URL that points to the Raspberry Pi Foundation’s own Raspbian mirror.
Switching this to the mirror we selected in step 2 is as simple as swapping out the URL with the one you decided on.
Below is an example of the text that you need to replace and an example of a URL that we will be using to replace it. In our case, we are using the mirror provided by AARnet.
6. Once you have finished modifying the file, it should look something like the text we have below.
Of course, you will be using the mirror that you got in step 2 and not our example.
deb http://mirror.aarnet.edu.au/pub/raspbian/raspbian stretch main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
When you are happy with the changes, go ahead and save the file by pressing CTRL + X then Y and finally ENTER.
7. Now that we have updated the sources.listfile we need to go ahead and run an update. This will update the local package list so that it will retrieve packages from the new repository.
sudo apt-get update
8. Hopefully, at this point, your Raspbian installation would have successfully updated the package list and will now be retrieving the lists from them without issue.
If you see any errors, then make sure that you entered in the correct URL from the Raspbian mirror list or try using a different mirror that is available in your country.
I hope that this tutorial has shown you all you need to know about changing the Raspbian repository mirror. If you have any feedback, tips or anything else, then please don’t hesitate to leave a comment below.