Recently on trying to install some AUR packages on arch, I was receiving a 404 code for several packages, what could mean that the package was removed or changed location. In terms of the mirrors I rarely had errors in the past, but it was a while I didn’t update or change those.
In order to get the best mirrors for your specific country and location you can use reflector.
First let’s install reflector:
sudo pacman -S reflector
The main arguments we can pass to reflector are the following:
sudo reflector -c <country> -l <number of mirrors> --save /etc/pacman.d/mirrorlist
For example you can run:
sudo reflector -c Netherlands -l 10 --save /etc/pacman.d/mirrorlist
This will output the 10 most recent mirrors syncronised, and the mirrors are sorted by speed as well.
Than run:
sudo pacman -Syyu
Ps: yy forces a refresh of the package databases from the new mirrors, ensuring pacman isn’t still working off a cached db from the old mirrors. The extra y compared to -Syu forces re-download even if the db appears up to date.
Reflector is a python script, you could check the internals as well by importing the libs on a python dev env and check the features and how it works:
cat /usr/bin/reflector
Source code link will be available at here
#!/usr/bin/python
import sys
import Reflector
sys.exit(Reflector.run_main(configure_logging=True))
It comes with a systemd service that can be enabled as well, and it’s running options can be configured at /etc/xdg/reflector/reflector.conf:
cat /etc/xdg/reflector/reflector.conf
# Reflector configuration file for the systemd service.
#
# Empty lines and lines beginning with "#" are ignored. All other lines should
# contain valid reflector command-line arguments. The lines are parsed with
# Python's shlex modules so standard shell syntax should work. All arguments are
# collected into a single argument list.
#
# See "reflector --help" for details.
# Recommended Options
# Set the output path where the mirrorlist will be saved (--save).
--save /etc/pacman.d/mirrorlist
# Select the transfer protocol (--protocol).
--protocol https
# Select the country (--country).
# Consult the list of available countries with "reflector --list-countries" and
# select the countries nearest to you or the ones that you trust. For example:
# --country France,Germany
# Use only the most recently synchronized mirrors (--latest).
--latest 5
# Sort the mirrors by synchronization time (--sort).
--sort age
Check the man pages for the command, but you can get all info you want, like a country list which you can set the mirrors for example:
sudo reflector --list-countries
Country Code Count
-------------------- ---- -----
Albania AL 1
Armenia AM 3
Australia AU 20
Austria AT 12
Azerbaijan AZ 5
Bangladesh BD 4
Belarus BY 4
Belgium BE 9
Brazil BR 11
Bulgaria BG 7
Cambodia KH 2
Canada CA 41
Chile CL 11
China CN 43
Colombia CO 7
...