Automatically update Arch Linux mirrors

Josh Sherman
2 min read
Linux Arch Linux

Arch Linux is still my favorite Linux distro for desktop use and once you get it set up (which may take you a few tries, if it’s your first foray) it tends to be pretty solid. That is, until you start seeing 404 error messages when you run pacman, yay, or whatever your package manager du jour is.

These errors start to show up when you’re using a mirror that had went dark or is experiencing some intermittent issues.

Like all things Arch, there’s a package that can help you with this situation. It’s called reflector and makes it extremely easy to update your mirror list. It even has a systemd script that can be setup to run automatically and keep your mirror list up to date with the fastest servers based on your location.

To get started, you need to install the reflector package:

sudo pacman -S reflector

Once installed, you may want to update the configuration to only use mirrors from your country. First, you’ll want to check the list of available countries:

reflector --list-countries

I’m based in the US, so I want to use the United States mirrors. Once you know which country or countries you want to use, open the configuration file:

sudo vim /etc/xdg/reflector/reflector.conf

And add the line:

--country 'YOUR COUNTRY','OR COUNTRIES'

If so inclined, you can adjust any of the other configuration options as you see fit. Aside from adding in my country, I haven’t had any need to update anything else.

With everything configured, all we need to do is to enable and start the reflector.service and reflector.timer services. The reflector.service will update your mirror list on boot and gets triggered by the reflector.timer automatically, once per week.

sudo systemctl enable reflector.service reflector.timer
sudo systemctl start reflector.service reflector.timer

If you’re ever in the position that you need to update your mirror list right this moment, you can run the reflector.service to do so:

sudo systemctl start reflector.service

To check that things have run correctly, you can check out your mirrorlist file which will have the date/time (in UTC) of the last time the file was generated:

shell cat /etc/pacman.d/mirrorlist `

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

Related Articles