Skip to content

Use

Why do you see this notice?

The script of this project currently mainly serves Simplified Chinese users, but from the very beginning it was defined as a universal mirror switching script, providing many command options for customization, which is also one of the reasons why this project is now available to users of other languages. The script output is currently fixed in Simplified Chinese. With feedback and usage from users of other languages, the script may support Traditional Chinese and English in the future.

The documentation is translated with tools, and some professional terms below may be inaccurate. Corrections are welcome.

One-Click Execution Command#

bash <(curl -sSL https://linuxmirrors.cn/main.sh)
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh)
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)

Real-time sync, no delay. Recommended for use in mainland China network environments.

bash <(curl -sSL https://raw.gitcode.com/gh_mirrors/li/LinuxMirrors/raw/main/ChangeMirrors.sh)

This project has joined the GitHub acceleration plan, with a 1-hour sync delay.

bash <(curl -sSL https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/ChangeMirrors.sh)
bash <(curl -sSL https://edgeone.linuxmirrors.cn/main.sh)

Not supported in mainland China network environments.

bash <(curl -sSL https://linuxmirrors.cn/main.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors

Real-time sync, no delay. Recommended for use in mainland China network environments.

bash <(curl -sSL https://raw.gitcode.com/gh_mirrors/li/LinuxMirrors/raw/main/ChangeMirrors.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors

This project has joined the GitHub acceleration plan, with a 1-hour sync delay.

bash <(curl -sSL https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/ChangeMirrors.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors
bash <(curl -sSL https://edgeone.linuxmirrors.cn/main.sh) --abroad 
  1. Use the --abroad command option to use overseas mirrors

Not supported in mainland China network environments.

bash <(curl -sSL https://linuxmirrors.cn/main.sh) --edu 
  1. Use the --edu command option to use China education network mirrors
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --edu 
  1. Use the --edu command option to use China education network mirrors
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) --edu 
  1. Use the --edu command option to use China education network mirrors

Real-time sync, no delay. Recommended for use in mainland China network environments.

bash <(curl -sSL https://raw.gitcode.com/gh_mirrors/li/LinuxMirrors/raw/main/ChangeMirrors.sh) --edu 
  1. Use the --edu command option to use China education network mirrors

This project has joined the GitHub acceleration plan, with a 1-hour sync delay.

bash <(curl -sSL https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/ChangeMirrors.sh) --edu 
  1. Use the --edu command option to use China education network mirrors
bash <(curl -sSL https://edgeone.linuxmirrors.cn/main.sh) --edu 
  1. Use the --edu command option to use China education network mirrors

Not supported in mainland China network environments.

Usage Help

The tabs represent the built-in mirror types and script sources. Please check whether your target mirror supports your operating system before use. You can check in the Mirror List.
By default, the original mirror configuration will be automatically backed up. For more details, see the documentation below. If you are confused by some options during use, just press Enter all the way after selecting the mirror, which is the best practice.

About Mirror Selection (Must Read for New Users)

If you are not familiar with these mirrors, it is recommended to use Aliyun (high compatibility, strong availability) or USTC (fast speed). Don't worry about speed tests, the built-in mirrors generally do not differ much.
This project script is an automated operation and maintenance tool. It does not subjectively rank or customize mirrors. User choice should be free, which is also to better continue the spirit of open source software.

  • Run the script as ROOT user


    Switch command: sudo -i or su root. Different systems use different commands because some systems do not set a password for the ROOT account during initial installation (such as Ubuntu) or the system disables ROOT login by default.

  • It is recommended to use a modern SSH client


    If your terminal displays garbled Chinese, you will not be able to see the interactive content. Some GUI terminal apps may have unpredictable display issues. Some systems automatically enable SSH service; otherwise, see how to enable SSH.

  • If running the script for the first time on a new system


    The script relies on curl to fetch content, but some systems do not preinstall this package, resulting in Command not found errors. See About Command not found below for installation. The script itself is unrelated to curl or wget and does not download any content.

  • Interactive configuration is required during script execution


    Use arrow keys UpDownLeftRight or WASD to control options and press Enter to confirm. If interaction is abnormal, try resizing the terminal window and avoid full screen.

FAQ#

  • About Command not found error#

    This error is caused by the system not having the curl package installed. Install it as follows:

    apt-get install -y curl
    

    Debian   Ubuntu   Kali   Linux Mint   Deepin   Zorin OS   Armbian   Proxmox VE   Raspberry Pi OS   openKylin

    For new systems, run apt-get update first.

    dnf install -y curl || yum install -y curl
    

    Red Hat Enterprise Linux   CentOS   Rocky Linux   AlmaLinux   Fedora   openEuler   OpenCloudOS   Anolis OS

    zypper install curl
    
    pacman -S curl
    
    apk --no-cache add -f curl bash ncurses
    
    emerge --ask curl
    
    nix-env -iA nixos.curl
    
    Can't install? (Click to see more solutions)

    If your system's original mirror is invalid and you can't install curl, here are some emergency ways to fetch the script online:

    Works for most systems (except Alpine Linux). If python3 is missing, try python.

    python3 -c "import urllib.request; urllib.request.urlretrieve('https://linuxmirrors.cn/main.sh', 'main.sh')"
    

    Usually, systems without curl also lack wget, so this may not work.

    wget https://linuxmirrors.cn/main.sh
    

    If you have GUI access, open the link in a browser to download the script. Many systems preinstall Firefox.

    Then run the script:

    bash main.sh
    
    bash main.sh --abroad
    
    bash main.sh --edu
    

    If none of these work, copy the source code to a new .sh file and run it with bash.

  • Backup of original mirrors#

    The script automatically backs up the original mirror configuration. The backup path is the original file or directory with .bak appended, e.g., /etc/apt/sources.list => /etc/apt/sources.list.bak. If a backup exists, you will be prompted whether to overwrite it.

  • Restore backed up mirrors#

    cp -rf /etc/apt/sources.list.bak /etc/apt/sources.list
    apt-get update
    
    system_name="$(lsb_release -is | tr '[:upper:]' '[:lower:]')"
    cp -rf "/etc/apt/sources.list.d/${system_name}.sources.bak" "/etc/apt/sources.list.d/${system_name}.sources"
    apt-get update
    

    Debian   Ubuntu   Kali   Linux Mint   Deepin   Zorin OS   Armbian   Proxmox VE   Raspberry Pi OS   openKylin

    cp -rf /etc/yum.repos.d.bak /etc/yum.repos.d
    yum makecache
    

    Red Hat Enterprise Linux   CentOS   Rocky Linux   AlmaLinux   Fedora   openEuler   OpenCloudOS   Anolis OS

    cp -rf /etc/zypp/repos.d.bak /etc/zypp/repos.d
    zypper ref
    
    cp -rf /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
    pacman -Sy
    
    cp -rf /etc/apk/repositories.bak /etc/apk/repositories
    apk update -f
    
    cp -rf /etc/portage/make.conf.bak /etc/portage/make.conf
    [ -d /etc/portage/repos.conf ] && cp -rf /etc/portage/repos.conf/gentoo.conf.bak /etc/portage/repos.conf/gentoo.conf
    emerge --sync --quiet
    
    cp -rf /etc/nix/nix.conf.bak /etc/nix/nix.conf
    
  • How to enable SSH remote login#

    The commands and steps are for reference only and only cover some common distributions.

    • Check if SSH service is installed

      ls /etc | grep ssh
      

      If this folder does not exist, SSH is not installed. Install the openssh package with your package manager.
      Note that package names may differ; you can use openssh* as a wildcard.

    • Allow Root login

      cat /etc/ssh/sshd_config | grep -Eq "^[# ]?PermitRootLogin " ; [ $? -eq 0 ] && sed -i 's/^[# ]\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config || echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config
      
    • Enable password authentication

      cat /etc/ssh/sshd_config | grep -Eq "^[# ]?PasswordAuthentication " ; [ $? -eq 0 ] && sed -i 's/^[# ]\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config || echo -e "\nPasswordAuthentication yes" >> /etc/ssh/sshd_config
      
    • Start/restart SSH service

      ps -ef | grep -q ssh ; [ $? -eq 0 ] && systemctl restart sshd || systemctl enable --now sshd
      

      Service names may differ; if not sshd, try ssh.

  • No arrow key interactive UI#

    If you see a text input instead of the new arrow key UI, install the ncurses or nano package. The new interaction relies on the tput command.

  • About the script's online location#

    The project uses GitHub Action to automatically copy the source code to the docs directory after each commit for website publishing. The site is hosted on Netlify, with almost no risk of hijacking.

    You can also use the raw address from the code repository. This is just to explain why there are several different addresses; the default official site address is easier to remember and access.

  • About mirror download speed#

    First, see the recommendations in the Mirror List usage help. These are based on experience, but some users still worry about speed.

    The network latency (Ping) of a mirror is not directly related to download speed. Distance does not equal experience. Some mirrors have high bandwidth but poor speed due to load strategies.

    There are many open source speed test scripts written in C or Python. This project is written in Bash Shell and does not depend on third-party libraries. Bash is the most common scripting language for Linux operations and is preinstalled on most distributions, so users can run it directly without installing anything. This convenience cannot be replaced by other languages. However, Bash scripts may not easily achieve accurate speed testing; using other languages for this is reinventing the wheel.

  • About disabled repositories#

    Many systems have multiple repositories. The script follows the system default. Disabled repositories will not be enabled after running the script, but their URLs will be updated. To enable them:

    By default, deb-src and proposed are disabled. Uncomment the relevant lines in /etc/apt/sources.list to enable.

    Debian   Ubuntu   Kali   Linux Mint   Deepin   Zorin OS   Armbian   Proxmox VE   Raspberry Pi OS   openKylin

    Some repos are disabled by default. Set enabled=1 in the relevant repo files under /etc/yum.repos.d.

    Red Hat Enterprise Linux   CentOS   Rocky Linux   AlmaLinux   Fedora   openEuler   OpenCloudOS   Anolis OS

    Some repos are disabled by default. Set enabled=1 in the relevant repo files under /etc/zypp/repos.d.


Command Options (Advanced Usage)#

Name Meaning Value
--abroad Use overseas mirrors none
--edu Use China education network mirrors none
--source Specify mirror address (domain or IP) address
--source-epel Specify EPEL repository address (domain or IP) address
--source-security Specify Debian/Ubuntu security repo address (domain or IP) address
--source-vault Specify CentOS/AlmaLinux vault repo address (domain or IP) address
--source-portage Specify Gentoo portage repo address (domain or IP) address
--source-base-system Specify Linux Mint/Raspberry Pi OS base system repo address (domain or IP) address
--branch Specify mirror repository (path) repo name
--branch-epel Specify EPEL repository (path) repo name
--branch-security Specify Debian security repo (path) repo name
--branch-vault Specify CentOS/AlmaLinux vault repo (path) repo name
--branch-portage Specify Gentoo portage repo (path) repo name
--branch-base-system Specify Linux Mint/Raspberry Pi OS base system repo (path) repo name
--codename Specify Debian/openKylin codename codename
--protocol Specify WEB protocol http or https
--use-intranet-source Prefer intranet mirror address true or false
--use-official-source Use official mirror of target OS true or false
--use-official-source-epel Use official EPEL repo true or false
--install-epel Install EPEL repository true or false
--backup Backup original mirrors true or false
--upgrade-software Upgrade packages true or false
--clean-cache Clean cache after upgrade true or false
--clean-screen Clear screen before running true or false
--print-diff Print diff before and after modification true or false
--only-epel Only switch EPEL repo none
--ignore-backup-tips Ignore backup overwrite prompt none
--pure-mode Pure mode, minimal output none
--help Show help menu none

Full mirror format: <WEB protocol>://<mirror address (domain or IP)>/<repo path>

Below are some advanced usage examples

  • Specify mirror address#

    bash <(curl -sSL https://linuxmirrors.cn/main.sh) --source mirror.example.com
    
  • Specify mirror repository#

    The repository here refers to the path after the mirror address, i.e., the branch on the mirror site. Although all are called repositories, it is easy to confuse.

    Main scenario: The target mirror site has a corresponding system repo but does not match the default rule in this script.

    Default repo names for each OS (click to expand)

    The script does not adapt to unique repo names of a single mirror site for compatibility.

    OS Name Names Involved
    Debian debian debian-archive
    Ubuntu ubuntu ubuntu-ports
    Kali Linux kali
    Linux Mint linuxmint ubuntu ubuntu-ports debian
    Deepin(深度) deepin
    Zorin OS ubuntu ubuntu-ports
    Armbian armbian
    Proxmox VE proxmox
    Raspberry Pi OS raspberrypi raspbian debian debian-archive
    Red Hat Enterprise Linux centos centos-stream centos-altarch centos-vault
    Fedora fedora fedora-archive
    CentOS centos centos-stream centos-altarch centos-vault
    Rocky Linux rocky
    AlmaLinux almalinux almalinux-vault
    openEuler openeuler
    OpenCloudOS opencloudos
    openKylin openkylin
    Anolis OS anolis
    openSUSE opensuse
    Arch Linux archlinux archlinuxarm
    Manjaro manjaro
    Alpine Linux alpine
    Gentoo gentoo gentoo-portage
    NixOS nix-channels

    Example:

    Use Aliyun mirror for Rocky Linux
    bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
      --source mirrors.aliyun.com \
      --branch rockylinux
    

    The repo name for Rocky Linux on Aliyun is rockylinux, not the default rocky, but you can override the default rule with the command option.

    Some systems configure multiple repos at once. See command options for details.

    Since the repo path is appended to the mirror address, you can use multi-level paths, e.g., --branch "linux/debian" -> https://mirrors.example.com/linux/debian

  • Switch EPEL repo only#

    EPEL (Extra Packages for Enterprise Linux) is an additional repo maintained by Fedora, mainly for Red Hat-based distributions except Fedora itself. Configuring EPEL is a common need and is recommended by default.

    Sometimes your desired mirror does not have EPEL. You can skip EPEL during the first run and then run:

    bash <(curl -sSL https://linuxmirrors.cn/main.sh) --only-epel
    

    For EPEL 7 (EOL), use the archive repo. For overseas networks, use --use-official-source-epel true to use the official repo.

  • Restore official mirrors#

    If you accidentally deleted the backup of the official mirror, use this command to restore. This skips mirror selection.

    bash <(curl -sSL https://linuxmirrors.cn/main.sh) --use-official-source true
    

    Some systems (e.g., Arch Linux) have no official mirror, so Aliyun will be used as a fallback.

  • Usage examples for specific systems#

    • About CentOS EOL#

      The script adapts to EOL CentOS 7/8 and CentOS Stream 8.

      • Mainland China


        Use as normal; most Chinese mirrors sync CentOS Vault.

      • International


        Use Tencent Cloud or Aliyun mirrors, or use --use-official-source true for the official repo.

      EPEL 7 is also EOL and is supported by the script.

    • Specify GNU/Linux Debian Security repo#

      For maximum security, use the official repo due to mirror sync delays.

      bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
        --source-security security.debian.org \
        --branch-security debian-security
      
    • Specify Debian-based codename#

      Usually for switching system versions. Example:

      bash <(curl -sSL https://linuxmirrors.cn/main.sh) --codename bookworm
      
      bash <(curl -sSL https://linuxmirrors.cn/main.sh) --codename testing
      

      After switching, run apt-get dist-upgrade and reboot, then rerun the script. Only changing the codename may cause compatibility issues later.

      If the script can't set the codename, you can manually replace it after running
      sed -i "s/$(lsb_release -cs)/your-codename/g" /etc/apt/sources.list
      
    • Switch Ubuntu EOL version mirrors#

      EOL means End Of Life. Non-LTS Ubuntu versions are supported for only 9 months. Old versions are removed from the main repo and may require using the Ubuntu Old Releases repo.

      See the official Wiki for version support and check each mirror for Ubuntu Old Releases support.

      bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
        --source mirrors.ustc.edu.cn \
        --branch ubuntu-old-releases
      
    • Arch Linux use Chinese community repo#

      This script does not support this extra repo. For reference, use:

      SOURCE="https://mirrors.aliyun.com/archlinuxcn"
      grep -q "\[archlinuxcn\]" /etc/pacman.conf || echo -e "[archlinuxcn]\nServer = ${SOURCE}/\$arch" >>/etc/pacman.conf
      
  • Unattended (automation)#

    To run without interaction, use at least the following options. Recommended for experienced users.

    Example Command
    bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
      --source mirror.example.com \
      --protocol http \
      --use-intranet-source false \
      --install-epel true \
      --backup true \
      --upgrade-software false \
      --clean-cache false \
      --ignore-backup-tips
    

    If you get an "invalid option" error, check the option validity and whitespace encoding. Each option is written on a separate line for readability.

  • Pure mode#

    For developers: when enabled, script output is minimized. Recommended for use with other options in non-interactive mode.

    bash <(curl -sSL https://linuxmirrors.cn/main.sh) --pure-mode
    

    Scrolling command logs may have unpredictable display issues, but no problems have been found so far.


Customizing the Script#

If you are a developer of another project and want to create a custom script based on this project, refer to the following. Some maintainers of China education network mirrors have already done so.

  1. It is not recommended to modify the core logic. Keep in sync with the upstream source code. The script execution order is controlled by the main function and is clear.
  2. You can simply remove irrelevant content, e.g., clear the mirror list arrays mirror_list_(default|edu|abroad|extranet|intranet), e.g., mirror_list_default=()
  3. To customize script output, modify the run_start, run_end, and print_title functions.
  4. To add custom shell content, see the execution order in main. Insert content directly or encapsulate in a function.
  5. To reduce script size, delete unnecessary content. Besides the mirror lists, you can remove some modules:
    1. Keep the original structure; empty out the function bodies if not needed.
    2. Remove unused OS repo content gen_repo_files_xxx, which takes up over 60% of the script.
    3. Remove unused feature modules, e.g., handle_command_options, backup_original_mirrors, upgrade_software.
  6. Main configuration is controlled by unified variables, as are command options. These global variables are all uppercase and use underscores. See the table below. Declare them at the top of the script (reserved comment area) for quick customization.
Variable Meaning Value Type
SOURCE Specify mirror address (domain or IP) address
SOURCE_EPEL Specify EPEL repo address (domain or IP) address
SOURCE_SECURITY Specify Debian/Ubuntu security repo address (domain or IP) address
SOURCE_VAULT Specify CentOS/AlmaLinux vault repo address (domain or IP) address
SOURCE_PORTAGE Specify Gentoo portage repo address (domain or IP) address
SOURCE_BASE_SYSTEM Specify Linux Mint/Raspberry Pi OS base system repo address (domain or IP) address
SOURCE_BRANCH Specify mirror repo (path) repo name
SOURCE_EPEL_BRANCH Specify EPEL repo (path) repo name
SOURCE_SECURITY_BRANCH Specify Debian security repo (path) repo name
SOURCE_VAULT_BRANCH Specify CentOS/AlmaLinux vault repo (path) repo name
SOURCE_PORTAGE_BRANCH Specify Gentoo portage repo (path) repo name
SOURCE_BASE_SYSTEM_BRANCH Specify Linux Mint/Raspberry Pi OS base system repo (path) repo name
DEBIAN_CODENAME Specify Debian/openKylin codename codename
USE_INTRANET_SOURCE Prefer intranet mirror address true or false
USE_OFFICIAL_SOURCE Use official mirror of target OS true or false
USE_OFFICIAL_SOURCE_EPEL Use official EPEL repo true or false
WEB_PROTOCOL Specify WEB protocol http or https
INSTALL_EPEL Install EPEL repository true or false
ONLY_EPEL Only switch EPEL repo true or false
BACKUP Backup original mirrors true or false
IGNORE_BACKUP_TIPS Ignore backup overwrite prompt true or false
UPGRADE_SOFTWARE Upgrade packages true or false
CLEAN_CACHE Clean cache after upgrade true or false
CLEAN_SCREEN Clear screen before running true or false
PRINT_DIFF Print diff before and after modification true or false
PURE_MODE Pure mode, minimal output true or false

Some variables have defaults. Unused variables do not need to be declared as empty strings. If a configuration is missing, interaction may occur.