-
-
Notifications
You must be signed in to change notification settings - Fork 1
Arch Linux Reflector Guide
Complete beginner-friendly guide to Reflector, a tool for ranking and updating Arch Linux mirror lists to improve download speeds and reliability.
- What is Reflector?
- Installing Reflector
- Basic Usage
- Understanding Reflector Options
- Common Commands and Examples
- Ranking Mirrors Explained
- Refreshing Package Database
- Automating Mirror Updates
- Troubleshooting
- Summary
Reflector is a Python script that retrieves and ranks the latest Arch Linux mirrors by speed and updates the mirror list file (/etc/pacman.d/mirrorlist).
What Reflector does:
- Tests mirror speeds: Downloads a small file from each mirror to measure speed
- Ranks mirrors: Sorts mirrors by download speed (fastest first)
- Filters mirrors: Can filter by country, protocol (HTTP/HTTPS), and other criteria
- Updates mirror list: Automatically saves the ranked mirrors to your mirror list file
Why use Reflector?
- Faster downloads: Uses the fastest available mirrors for your location
- Better reliability: Tests mirrors to ensure they're working
- Automatic updates: Can automatically update your mirror list
- Easy to use: Simple command-line interface
What is a mirror?
- A mirror is a server that contains a copy of the Arch Linux package repository
- Multiple mirrors exist worldwide to distribute download load
- Closer mirrors typically provide faster download speeds
- If one mirror fails, pacman tries the next one in the list
Reflector may not be included in vanilla Arch Linux installations. It's recommended to check if it's installed first, and if not, install it manually using pacman. This is a common point of confusion for new Arch users.
Why it may not be included:
- Arch Linux follows a minimal installation philosophy
- Only essential packages are typically included by default
- Reflector is an optional utility tool
- Installation varies depending on the installation method
When you need it:
- If you want to automatically rank and update mirrors
- If you want faster download speeds
- If you want to automate mirror management
- If you're experiencing slow package downloads
Before installing, check if Reflector is already installed:
which reflectorWhat this does:
- Checks if the
reflectorcommand exists - Shows the path if installed
- Shows nothing if not installed
If installed, you'll see:
/usr/bin/reflector
If not installed, you'll see:
(nothing - command not found)
Alternative check:
pacman -Q reflectorWhat this does:
- Checks if the reflector package is installed
- Shows version if installed
- Shows error if not installed
If installed, you'll see:
reflector 2024.1-1
If not installed, you'll see:
error: package 'reflector' was not found
If Reflector is not installed, install it using pacman:
sudo pacman -S reflectorWhat this does:
-
sudo: Runs the command with administrator privileges (needed to install packages) -
pacman: The package manager for Arch Linux -
-S: Synchronize (install) the specified package -
reflector: The name of the package to install
What you'll see:
The system will show you what will be installed and ask for confirmation. Type Y and press Enter to proceed.
Example output:
:: Synchronizing package databases...
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...
Packages (1) reflector-2024.1-1
Total Download Size: 0.10 MiB
Total Installed Size: 0.50 MiB
:: Proceed with installation? [Y/n]
If you see "package not found":
- Make sure your mirror list is working
- Try updating your package database first:
sudo pacman -Syy - Check your internet connection
- Verify your mirror list is valid
If installation fails:
- Check your internet connection
- Update package database:
sudo pacman -Syy - Try a different mirror (see troubleshooting section)
- Check for system updates:
sudo pacman -Syu
After installation, verify Reflector is installed and working:
reflector --versionWhat this does:
- Shows the installed version of Reflector
- Confirms the installation was successful
- Verifies the command is accessible
Expected output:
Reflector 2024.1
If you see "command not found":
- Installation may have failed
- Try installing again:
sudo pacman -S reflector - Check if the package was actually installed:
pacman -Q reflector - Restart your terminal session
Test Reflector functionality:
reflector --list-countriesWhat this does:
- Lists all available countries
- Tests if Reflector can access mirror information
- Verifies Reflector is working correctly
Expected output:
Available countries:
Australia
Austria
Belgium
Brazil
...
United States
...
CachyOS:
- Reflector may or may not be pre-installed
- Install the same way:
sudo pacman -S reflector - Uses the same Arch Linux repositories
Manjaro:
- Reflector is usually not pre-installed
- Install the same way:
sudo pacman -S reflector - May need to enable Arch repositories if not already enabled
EndeavourOS:
- Reflector is usually not pre-installed
- Install the same way:
sudo pacman -S reflector
ArcoLinux:
- Reflector may be pre-installed
- Check first with:
which reflector - Install if needed:
sudo pacman -S reflector
The most common Reflector command is:
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat this command does:
- Gets the 20 latest mirrors (most recently synced)
- Filters to only HTTPS mirrors (more secure)
- Sorts mirrors by download rate (fastest first)
-
Saves the result to
/etc/pacman.d/mirrorlist
Breaking it down:
-
sudo: Required because we're modifying a system file -
reflector: The command to run -
--latest 20: Get the 20 most recently synced mirrors -
--protocol https: Only use HTTPS mirrors -
--sort rate: Sort by download speed -
--save /etc/pacman.d/mirrorlist: Save to the mirror list file
After updating your mirror list, refresh the package database:
sudo pacman -SyyWhat this does:
-
-Syy: Force refresh of all package databases - Downloads fresh package lists from your new mirrors
- Ensures pacman uses the updated mirror list
Why refresh?
- The package database needs to be updated to use the new mirrors
-
-Syyforces a complete refresh (the doubleymeans "force refresh") - This ensures all repositories are updated with the new mirror list
What it does: Gets only the most recently synced mirrors.
Example:
--latest 20What this means:
- Only includes mirrors that have synced in the last 20 hours
- Ensures mirrors are up-to-date
- Excludes mirrors that haven't synced recently
Why use it:
- Recent mirrors are more likely to be current
- Reduces the chance of downloading outdated packages
- Helps ensure mirror reliability
Common values:
-
--latest 5: Very recent mirrors only (5 hours) -
--latest 10: Recent mirrors (10 hours) -
--latest 20: Moderately recent mirrors (20 hours) - Recommended -
--latest 50: Less strict (50 hours)
What it does: Filters mirrors by protocol (HTTP or HTTPS).
Options:
-
http: Unencrypted connections -
https: Encrypted connections (more secure)
Example:
--protocol httpsWhat this means:
- Only uses mirrors that support HTTPS
- All connections are encrypted
- More secure than HTTP
Why use HTTPS:
- Security: Encrypts data in transit
- Privacy: Prevents interception of downloads
- Verification: Ensures package integrity
When to use HTTP:
- If HTTPS mirrors are slow in your area
- For testing purposes
- If you're on a trusted network
Example with HTTP:
--protocol httpWhat it does: Filters mirrors by country.
Example:
--country "United States"What this means:
- Only includes mirrors located in the specified country
- Typically faster if you're in that country
- Reduces latency
Multiple countries:
--country "United States,Canada"What this means:
- Includes mirrors from both countries
- Useful if you're near a border
- Provides more mirror options
Common countries:
"United States""Canada""United Kingdom""Germany""France""Australia""Japan"
Find your country name:
reflector --list-countriesWhat this does:
- Lists all available countries
- Shows exact country names to use
- Helps you find the correct spelling
What it does: Filters mirrors by how recently they synced (in hours).
Example:
--age 6What this means:
- Only includes mirrors that synced within the last 6 hours
- More strict than
--latest - Ensures very fresh mirrors
Difference from --latest:
-
--latest: Gets the N most recent mirrors -
--age: Gets all mirrors that synced within N hours
When to use:
- If you want very fresh mirrors
- If you're concerned about mirror freshness
- For critical updates
What it does: Sorts mirrors by a specific criteria.
Available criteria:
-
rate- Sort by download speed (fastest first)--sort rate
- Best for: Getting the fastest mirrors
- What it does: Tests download speed and sorts by fastest
- Recommended: Yes, for most users
-
delay- Sort by connection delay (lowest first)--sort delay
- Best for: Low latency connections
- What it does: Sorts by ping time
- Use when: You want responsive connections
-
score- Sort by mirror score (highest first)--sort score
- Best for: Overall mirror quality
- What it does: Uses a combination of factors
- Use when: You want balanced performance
-
country- Sort by country name (alphabetical)--sort country
- Best for: Organizing by location
- What it does: Groups mirrors by country
- Use when: You want geographic organization
-
age- Sort by sync age (newest first)--sort age
- Best for: Getting the freshest mirrors
- What it does: Sorts by how recently mirrors synced
- Use when: Freshness is more important than speed
Most common:
--sort rate- Recommended for most users
- Gets the fastest mirrors
- Best balance of speed and reliability
What it does: Saves the generated mirror list to a file.
Example:
--save /etc/pacman.d/mirrorlistWhat this means:
- Saves the ranked mirrors to the mirror list file
- Overwrites the existing mirror list
- This is the file pacman uses
Important:
- Always use
sudowhen saving to/etc/pacman.d/mirrorlist - This file requires administrator privileges to modify
- Back up the original file first (see troubleshooting section)
Save to a different file:
--save /tmp/mirrorlist.newWhat this does:
- Saves to a temporary file
- Allows you to review before replacing
- Useful for testing
What it does: Limits the number of mirrors in the output.
Example:
--number 10What this means:
- Only includes the top 10 mirrors after sorting
- Reduces mirror list size
- Faster mirror selection for pacman
Why limit mirrors:
- Smaller list = faster mirror selection
- Top mirrors are usually sufficient
- Reduces configuration complexity
Common values:
-
--number 5: Very few mirrors (fast selection) -
--number 10: Moderate number (balanced) -
--number 20: More mirrors (better redundancy)
Note: This is different from --latest. --latest filters by sync time, --number limits the final output.
What it does: Sets the number of threads for testing mirrors.
Example:
--threads 5What this means:
- Tests 5 mirrors simultaneously
- Faster execution
- Uses more network bandwidth
Default: Usually 1 thread
When to increase:
- If you have fast internet
- If you want faster mirror testing
- If testing many mirrors
When to decrease:
- If you have slow internet
- If you want to be conservative with bandwidth
- If you're on a metered connection
What it does: Only includes mirrors that have completed syncing to a certain percentage.
Example:
--completion-percent 100What this means:
- Only includes mirrors that are 100% synced
- Ensures complete mirrors
- Excludes partially synced mirrors
Common values:
-
100: Only fully synced mirrors (recommended) -
99: Allows mirrors that are 99% synced -
95: More lenient
What it does: Excludes mirrors matching a pattern.
Example:
--exclude ".*\.edu"What this means:
- Excludes mirrors from .edu domains
- Useful for avoiding slow academic mirrors
- Can exclude specific domains
Use cases:
- Excluding known slow mirrors
- Avoiding specific domains
- Filtering problematic mirrors
What it does: Only includes mirrors matching a pattern.
Example:
--include ".*\.org"What this means:
- Only includes mirrors from .org domains
- Very restrictive filtering
- Useful for specific requirements
Command:
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat it does:
- Gets 20 most recent mirrors
- Only HTTPS mirrors
- Sorts by download speed
- Saves to mirror list
When to use:
- Most common use case
- Good balance of speed and security
- Recommended for most users
After running:
sudo pacman -SyyCommand:
sudo reflector --country "United States" --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat it does:
- Only US mirrors
- 20 most recent
- HTTPS only
- Sorted by speed
When to use:
- If you're in the United States
- Want to prioritize local mirrors
- Want faster local connections
After running:
sudo pacman -SyyCommand:
sudo reflector --country "United States,Canada" --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat it does:
- Mirrors from US and Canada
- 20 most recent
- HTTPS only
- Sorted by speed
When to use:
- If you're near the US-Canada border
- Want more mirror options
- Want geographic diversity
After running:
sudo pacman -SyyCommand:
sudo reflector --age 6 --protocol https --sort rate --number 10 --save /etc/pacman.d/mirrorlistWhat it does:
- Only mirrors synced in last 6 hours
- HTTPS only
- Sorted by speed
- Top 10 mirrors only
When to use:
- Want very fresh mirrors
- Want minimal mirror list
- Prioritize freshness over quantity
After running:
sudo pacman -SyyCommand:
sudo reflector --latest 50 --protocol https --sort rate --number 20 --save /etc/pacman.d/mirrorlistWhat it does:
- 50 most recent mirrors (any country)
- HTTPS only
- Sorted by speed
- Top 20 fastest
When to use:
- Want fastest mirrors regardless of location
- Have very fast international connection
- Want maximum speed
After running:
sudo pacman -SyyCommand:
sudo reflector --latest 20 --protocol https --sort delay --number 10 --save /etc/pacman.d/mirrorlistWhat it does:
- 20 most recent mirrors
- HTTPS only
- Sorted by connection delay (ping time)
- Top 10 lowest latency
When to use:
- Want responsive connections
- Low latency is more important than raw speed
- For interactive package operations
After running:
sudo pacman -SyyCommand:
sudo reflector --latest 20 --protocol https --sort rate --save /tmp/mirrorlist.newWhat it does:
- Generates mirror list
- Saves to temporary file
- Allows review before replacing
Review the file:
cat /tmp/mirrorlist.newIf satisfied, replace the original:
sudo mv /tmp/mirrorlist.new /etc/pacman.d/mirrorlistWhen to use:
- Want to review mirrors before applying
- Testing different configurations
- Being cautious
After replacing:
sudo pacman -SyyCommand:
sudo reflector --latest 20 --protocol http --sort rate --save /etc/pacman.d/mirrorlistWhat it does:
- 20 most recent mirrors
- HTTP only (not HTTPS)
- Sorted by speed
When to use:
- HTTPS mirrors are slow in your area
- On a trusted network
- Need maximum speed
Security note:
- HTTP is not encrypted
- Use only on trusted networks
- HTTPS is recommended when possible
After running:
sudo pacman -SyyWhat happens when you run Reflector:
-
Mirror Discovery
- Reflector gets a list of all available mirrors
- Filters mirrors based on your criteria (country, protocol, etc.)
-
Speed Testing
- Downloads a small test file from each mirror
- Measures download speed
- Records connection delay (ping time)
-
Ranking
- Sorts mirrors by your chosen criteria (rate, delay, etc.)
- Fastest/best mirrors first
- Slowest/worst mirrors last
-
Output
- Generates a ranked mirror list
- Saves to
/etc/pacman.d/mirrorlist - pacman uses this list for downloads
What it measures:
- How fast data can be downloaded from the mirror
- Measured in bytes per second (or similar)
- Tests actual download performance
Best for:
- Large package downloads
- System updates
- Maximum download speed
Example:
--sort rateWhat it measures:
- Time for a packet to reach the mirror and return (ping)
- Measured in milliseconds
- Lower is better
Best for:
- Responsive connections
- Small package downloads
- Interactive operations
Example:
--sort delayWhat it measures:
- Combination of factors
- Overall mirror quality
- Balanced metric
Best for:
- General use
- Balanced performance
- When unsure which to choose
Example:
--sort scoreBenefits of ranked mirrors:
- Faster downloads: Fastest mirrors tried first
- Better reliability: Tested mirrors are more reliable
- Automatic optimization: No manual configuration needed
- Geographic optimization: Can prioritize local mirrors
Without ranking:
- pacman tries mirrors in order (may be slow)
- No speed testing
- Manual configuration required
- May use slow mirrors
After updating your mirror list, you should refresh the package database:
sudo pacman -SyyWhat this does:
-
-S: Synchronize (refresh) package databases -
yy: Force refresh (doubley= force) - Downloads fresh package lists from new mirrors
Why it's important:
- New mirrors need to be contacted
- Package database needs updating
- Ensures pacman uses new mirror list
- Prevents stale package information
What -Syy means:
-
-S: Synchronize package databases - First
y: Refresh package databases - Second
y: Force refresh (even if up-to-date)
Difference from -Sy:
-
-Sy: Normal refresh (skips if up-to-date) -
-Syy: Force refresh (always refreshes)
When to use -Syy:
- After changing mirror list
- After repository configuration changes
- When package database seems stale
- After Reflector updates
When to use -Sy:
- Normal package database updates
- Regular system updates
- When you want to check for updates
Warning:
-
-Syycan cause issues if used incorrectly - Only use when necessary (after mirror changes)
- For normal updates, use
-Syuinstead
Step 1: Update Mirrors
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistStep 2: Refresh Package Database
sudo pacman -SyyStep 3: Update System (Optional)
sudo pacman -SyuWhat this workflow does:
- Updates mirror list with fastest mirrors
- Refreshes package database with new mirrors
- Updates system packages (if desired)
Create a systemd service file:
sudo nano /etc/systemd/system/reflector.serviceAdd this content:
[Unit]
Description=Pacman mirror list update
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat this does:
- Creates a service that runs Reflector
- Waits for network to be online
- Updates mirror list when triggered
Create a systemd timer file:
sudo nano /etc/systemd/system/reflector.timerAdd this content:
[Unit]
Description=Run reflector weekly
Requires=reflector.service
[Timer]
OnCalendar=weekly
RandomizedDelaySec=0
Persistent=true
[Install]
WantedBy=timers.targetWhat this does:
- Runs Reflector weekly
- Random delay of 0 seconds (can be increased)
- Persistent (runs if missed)
Enable and start the timer:
sudo systemctl enable reflector.timer
sudo systemctl start reflector.timerWhat this does:
- Enables timer to start on boot
- Starts the timer immediately
- Mirrors will update weekly automatically
Check timer status:
systemctl status reflector.timerWhat this shows:
- When timer will run next
- Timer status
- Last run time
Edit crontab:
sudo crontab -eAdd this line:
0 0 * * 0 /usr/bin/reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist && /usr/bin/pacman -Syy
What this does:
- Runs every Sunday at midnight
- Updates mirrors
- Refreshes package database
Cron format explanation:
-
0 0 * * 0: Sunday at 00:00 (midnight) -
* * * * *: minute hour day month weekday
Error message:
Permission denied: /etc/pacman.d/mirrorlist
Solution:
Use sudo when saving to /etc/pacman.d/mirrorlist:
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlistWhat this does:
-
sudogives administrator privileges - Required for modifying system files
- Always use
sudofor this file
Error message:
No mirrors found matching criteria
Possible causes:
- Too restrictive filters
- Network connectivity issues
- Country name misspelled
Solutions:
1. Check country name:
reflector --list-countries2. Use less restrictive filters:
sudo reflector --latest 50 --protocol https --sort rate --save /etc/pacman.d/mirrorlist3. Remove country filter:
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist4. Check network:
ping -c 3 8.8.8.8Problem: Reflector takes a long time to test mirrors.
Solutions:
1. Reduce number of mirrors tested:
sudo reflector --latest 10 --protocol https --sort rate --save /etc/pacman.d/mirrorlist2. Use fewer threads (if using --threads):
sudo reflector --latest 20 --protocol https --sort rate --threads 1 --save /etc/pacman.d/mirrorlist3. Test to temporary file first:
sudo reflector --latest 20 --protocol https --sort rate --save /tmp/mirrorlist.newBefore running Reflector, backup your current mirror list:
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backupWhat this does:
- Creates a backup copy
- Allows restoration if needed
- Good practice before changes
Restore backup if needed:
sudo cp /etc/pacman.d/mirrorlist.backup /etc/pacman.d/mirrorlistProblem: Download speeds are still slow after updating mirrors.
Solutions:
1. Try different sort criteria:
sudo reflector --latest 20 --protocol https --sort delay --save /etc/pacman.d/mirrorlist2. Increase number of mirrors:
sudo reflector --latest 50 --protocol https --sort rate --number 30 --save /etc/pacman.d/mirrorlist3. Check your internet connection:
speedtest-cli4. Try HTTP if HTTPS is slow:
sudo reflector --latest 20 --protocol http --sort rate --save /etc/pacman.d/mirrorlistProblem:
Errors when running pacman -Syy after mirror update.
Solutions:
1. Verify mirror list is valid:
cat /etc/pacman.d/mirrorlist2. Test a mirror manually:
curl -I https://mirror.example.com/archlinux/core/os/x86_64/3. Restore backup and try again:
sudo cp /etc/pacman.d/mirrorlist.backup /etc/pacman.d/mirrorlist
sudo pacman -SyyError message:
command not found: reflector
Solution: Install Reflector:
sudo pacman -S reflectorWhat this does:
- Installs the Reflector package
- Makes the command available
- Required before first use
What Reflector does:
- Tests and ranks Arch Linux mirrors by speed
- Updates your mirror list automatically
- Improves download speeds
Most common command:
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
sudo pacman -SyyImportant options:
-
--latest <number>: Get most recent mirrors -
--protocol https: Use secure connections -
--sort rate: Sort by download speed -
--country "<country>": Filter by country -
--save <file>: Save to mirror list file
After updating mirrors:
- Always run
sudo pacman -Syyto refresh package database - This ensures pacman uses the new mirrors
- Required for changes to take effect
Best practices:
- Backup mirror list before changes
- Use HTTPS when possible
- Test to temporary file first if unsure
- Automate with systemd timer
- Refresh package database after updates
- Arch Linux Pacman Configuration - Configure pacman
- Arch Linux Package Management - Package management
- Arch Linux Repository Configuration - Repository setup
- ArchWiki Reflector: https://wiki.archlinux.org/title/Reflector