Finding the Most Up-to-Date and Fastest Arch Linux Mirrors

Meet Reflector, the Arch Linux tool that optimizes your Pacman experience by selecting the fastest and most up-to-date mirrors. Here's how to use it.

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 rsyncCode language: Bash (bash)
Installing Reflector
Installing Reflector

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.backupCode 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/.

Generate mirrorlist file via Arch's online tool.
Generate mirrorlist file via Arch’s online tool.

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/mirrorlistCode 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/mirrorlistCode language: Bash (bash)
Get the ten most recently synced Arch's mirrors.
Get the ten most recently synced Arch’s mirrors.

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/mirrorlistCode 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-countriesCode language: Bash (bash)
Country codes.
Country codes.

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/mirrorlistCode 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/mirrorlistCode 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/mirrorlistCode 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/mirrorlistCode 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.confCode language: Bash (bash)
Reflector's service configuration file.
Reflector’s service configuration file.

Save the file and exit. Next, to enable Reflector to automatically create the “mirrorlist” file, run:

sudo systemctl enable --now reflector.timerCode 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-timersCode language: Bash (bash)
Check reflector.timer
Check reflector.timer

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.serviceCode language: Bash (bash)
Enable Reflector service.

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.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%