Skip to main content
Crusoe Support Help Center home page
Crusoe

How-To Switch Ubuntu to Alternative Mirrors When Default Repositories Are Unavailable

Sagar Lulla
Sagar Lulla
Updated

Last Updated: Dec 15th, 2025

Introduction

Ubuntu uses online repositories (hosted at domains like archive.ubuntu.com or security.ubuntu.com) to distribute software packages and updates. Sometimes, these default repositories may be unavailable due to outages, maintenance, or slow connectivity.

When running apt update or installing packages, you may encounter errors when Ubuntu cannot connect to its repositories (e.g., archive.ubuntu.com, security.ubuntu.com)

Example Error:

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease  
   Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::101). - connect (101: Network is unreachable)  
   Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::103). - connect (101: Network is unreachable)  
   Could not connect to archive.ubuntu.com:80 (91.189.91.81), connection timed out  
   Could not connect to archive.ubuntu.com:80 (185.125.190.81), connection timed out  

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease  
   Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4002:1::102). - connect (101: Network is unreachable)

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease  
   Connection failed [IP: 185.125.190.82 80]

To avoid downtime, you can switch your system to use alternative Ubuntu mirrors. Mirrors are replicas of the official repositories, hosted worldwide by universities, companies, or community organizations.

This guide explains how to:

  • Identify your current repository URLs

  • Safely switch to alternative mirrors

  • Revert back when the defaults are restored

  • Apply this process to any Ubuntu repository endpoint, not just archive.ubuntu.com or security.ubuntu.com


Prerequisites

  • A system running Ubuntu (20.04, 22.04, or later).

  • sudo privileges.

  • Network access to public Ubuntu mirrors.

  • Basic familiarity with editing files on Linux.


Step-by-Step Instructions

1. Identify Current Repository Sources

Ubuntu stores repository settings in /etc/apt/sources.list. To check which repositories your system is using:

cat /etc/apt/sources.list | grep -v '^#'

This shows all active repository entries.


2. Backup Your Sources

Before making changes, create a backup:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak.$(date +%F)

If needed, you can revert later.


3. Use Automatic Mirror Selection

Instead of replacing the default Canonical repositories, you can keep them and add fallback mirrors from the official Ubuntu mirror list.

Edit /etc/apt/sources.list and add the following above or below the default entries:

# Default Canonical repos
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse

# Mirror fallback (auto-selected from mirrors.ubuntu.com)
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-backports main restricted universe multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-security main restricted universe multiverse

This ensures:

  • Canonical repos are tried first.

  • If they are unavailable, apt automatically falls back to an available mirror.

Update the package cache:

sudo apt-get update

4. Verify New Mirror is Being Used

grep -E "mirrors.kernel.org" /etc/apt/sources.list

You should see your sources updated to the new mirror.

Then confirm updates are working:

sudo apt-get upgrade -y

5. Revert if Needed

To restore your original sources:

sudo mv /etc/apt/sources.list.bak.* /etc/apt/sources.list
sudo apt-get update

Example

If multiple repositories are unreachable:

Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Could not connect to archive.ubuntu.com:80
Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Could not connect to security.ubuntu.com:80

After switching to a mirror:

Get:1 http://mirrors.kernel.org/ubuntu jammy InRelease [270 kB]
Get:2 http://mirrors.kernel.org/ubuntu jammy-security InRelease [129 kB]
Fetched 15.3 MB in 3s (4,500 kB/s)
Reading package lists... Done

Common Issues & Resolutions

Issue: The chosen mirror is slow or incomplete.

Issue: You want the fastest mirror automatically.

  • Resolution: Use the netselect-apt tool (sudo apt-get install netselect-apt) to generate a sources.list with the fastest mirror near you.

Issue: curl to the old repo URL still fails.

  • Resolution: The mirror change only affects apt, not direct requests to the old domain. Use curl against the new mirror instead.


Additional Resources

Related to

Was this article helpful?

0 out of 0 found this helpful

Still need help?

Our support team is ready to assist you with any questions.

Have more questions? Submit a request

Recently Viewed

Comments

0 comments

Article is closed for comments.