Okay, you’ve installed Arch. Congratulations! One of the first things you should do after that is update your system. Since Arch Linux is a rolling-release distro, regular updates via Pacman are a must to keep it healthy.
However, this can be annoying if you experience slow software download speed. But what if I told you that among the vast selection of tools in Arch, there is one that can significantly boost the speed of your updates?
Meet Reflector, a powerful utility in the Arch arsenal, with the help of which such inconveniences become a thing of the past.
It helps users select the fastest and most up-to-date mirrors for the Pacman package manager, which can significantly speed up software installation and updating. Let me show you how to use it. But before that, let’s say a few words about the tool itself.
What is Reflector?
Reflector is a Python script designed for Arch Linux systems. It scans and selects the fastest and most synced mirrors based on bandwidth, response time, and when the mirror was last refreshed.
It also updates the mirror list (“/etc/pacman.d/mirrorlist“) for Pacman, ensuring you always have the best sources for your software updates and installations. By using Reflector, you can:
- Automatically rank mirrors based on speed and stability.
- Filter mirrors based on your geographical location.
- Update your mirror list regularly to ensure the fastest possible package downloads.
Reflector: Pick the Fastest Arch’s Mirrors Automatically
Here’s how to use the tool to find the fastest and most up-to-date mirrors providing the best speed to your computer for use with Pacman.
Install Reflector
Before optimizing your mirror list, you need to install Reflector. It is a simple task. Open your terminal and run the following command:
sudo pacman -S reflector rsync
Code language: Bash (bash)
This command will download and install Reflector along with any necessary dependencies.
Backup Your Current Mirrorlist
Next, it is a good idea to back up your existing mirror list in the file “/etc/pacman.d/mirrorlist” before making changes.
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
Code language: Bash (bash)
However, it is not critical because, if needed, you can easily recreate it using Arch’s online tool at https://archlinux.org/mirrorlist/.
Choose your preferred countries, typically your own or neighboring ones, and click the “Generate List” button. This will create text content you can copy and paste directly into the “/etc/pacman.d/mirrorlist” file.
Get the Most Up-To-Date Arch’s Mirrors
Not all mirrors are equally up-to-date, as the synchronization interval varies depending on how often the administrators of each mirror choose to set it. This means some of them may have newer software more quickly than others.
We all want our Arch systems to use mirrors that provide the most actual software versions, meaning they have recently been synced with the main Arch servers. This is done very easily with the help of Reflector, as the command we need to execute is:
sudo reflector --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
As a result, you get the ten most recently synchronized mirrors automatically populated in your “/etc/pacman.d/mirrorlist” file, replacing its current contents and sorting them by download rate. You can easily view the final result by running:
cat /etc/pacman.d/mirrorlist
Code language: Bash (bash)
Additionally, it’s worth noting that the reflector
command operates silently in the background without showing any output while it runs. You might also see a multiple message like this:
[2024-06-21 08:34:52] WARNING: failed to rate http(s) download (https://mirrors.neusoft.edu.cn/archlinux/extra/os/x86_64/extra.db): Download timed out after 5 second(s).
[2024-06-21 08:34:58] WARNING: failed to rate http(s) download (https://md.mirrors.hacktegic.com/archlinux/extra/os/x86_64/extra.db): Download timed out after 5 second(s).
Code language: JavaScript (javascript)
Don’t worry about them. It doesn’t mean a problem with the Reflector itself; it simply indicates that the mirror didn’t respond within five seconds, the default timeout period that the Reflector uses for retrieving data.
Now, let’s break down the main options of the reflector
command and what each one means.
--latest
: Limit the list to the “n” most recently synchronized servers.--sort
: In that case, sort the mirrors list by “rate,” which means the download rate. The other possible options are “age,” “country,” “score,” and “delay.”--save
: Save the mirrors list as a file to the given path.
We can additionally improve the above command by telling Reflector to pick the five fastest servers from the last ten synchronized mirrors and list them in the “/etc/pacman.d/mirrorlist” file. To do this, add the --fastest
option and specify the number of servers you want. The command will look like this:
sudo reflector --latest 10 --sort rate --fastest 5 --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
Let’s now look at other practical options for the reflector
command.
Selecting Servers From a Specific Country(ies) Only
A handy feature of Reflector is the ability to test servers only located in a specific country, usually the same country as your Arch system. This means faster performance.
You can do this by using the --country
option. If you’re wondering how to find the correct codes for different countries, run the below command, and Reflector will display them.
reflector --list-countries
Code language: Bash (bash)
For example, to limit the servers to those located in the US only, you could use this:
sudo reflector --country "US" --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
Of course, we can add more countries if we want. Just list them one after the other, separated by commas. Here is an example with the US and Canada.
sudo reflector --country "US,CA" --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
If you want, you can use their full names instead of the country codes:
sudo reflector --country "United States,Canada" --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
Limiting Arch’s Mirrors by Protocol Used
Lastly, we’ll show you how to filter mirror servers based on their protocol. The possible options are “http,” “https,” and “ftp.” You can do this with the --protocol
option.
For example, here’s how to test and create a “mirrorlist” file with only “https” Arch’s mirror servers.
sudo reflector --protocol https --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
Code language: Bash (bash)
As with the country’s code, multiple protocols may be selected using commas (e.g., “http,https“).
Automating the Process
It’s important to realize that the fastest Arch mirror for you today might not be the fastest one tomorrow or next week. The same is true for the frequency of syncs; another mirror might start synchronizing more frequently.
This raises the question of whether you need to run the reflector
command regularly. The answer is yes. And while this might seem like a tedious chore, there’s good news.
Reflector includes a feature, a systemd timer, that once set up, will automatically handle this for you. It continually updates the “/etc/pacman.d/mirrorlist” file, freeing you from running it manually at regular intervals.
New to systemd timers? They are a scheduling tool in Linux, part of the systemd functionality, that triggers events at specified times, similar to a cron job. Now, back to the topic.
Reflector uses a configuration file located at “/etc/xdg/reflector/reflector.conf” to determine its default settings. Open it using your preferred terminal text editor and adjust the settings according to your needs.
sudo nano /etc/xdg/reflector/reflector.conf
Code language: Bash (bash)
Save the file and exit. Next, to enable Reflector to automatically create the “mirrorlist” file, run:
sudo systemctl enable --now reflector.timer
Code language: Bash (bash)
This will activate and start the timer to recreate the “mirrorlist.” That’s a weekly timer that calls the reflector service that runs the task itself.
You can check its status by running the command below. In the output, “reflector.timer” should be present.
sudo systemctl list-timers
Code language: Bash (bash)
But there’s an additional option. As we mentioned, Reflector offers its own service besides the systemd timer. If you want your “mirrorlist” file to be recreated every time your Arch system boots, based on the settings in “/etc/xdg/reflector/reflector.conf,” you can run:
sudo systemctl enable --now reflector.service
Code language: Bash (bash)
This enables and starts the Reflector’s service and recreates the file immediately.
Conclusion
With Reflector in your toolkit, managing Arch Linux mirrors becomes easier and downright convenient. This saves you time during updates and enhances your overall user experience. A well-maintained mirror list is key to enjoying the best that Arch has to offer, making each update swift and smooth.
For more information, visit the Reflector man page or the Arch Wiki. Thanks for using our guide! Feel free to share your thoughts in the comments section below.