Please enable Javascript to view the contents

各种包管理器的镜像源汇总

 ·  ☕ 5 分钟

众所周知,国内的程序员想要从各大包管理器的官方源上下载软件或者程序依赖是很痛苦的一件事,因为几乎所以的官方源都架设在国外,国内的 IP 从这些源上下东西就算不被墙那速度也是慢得令人发指。

不过好在我们有镜像源。今天我就来写一篇文章汇总一下各个包管理器的镜像源的设置方法。

感谢各大镜像站对开源做出的贡献!!!

Operating System

Archlinux

镜像源:清华大学开源软件镜像站

编辑 /etc/pacman.d/mirrorlist, 在文件的最顶端添加:

Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch 

更新软件包缓存:

1
sudo pacman -Syy

ArchlinuxCN

镜像源:清华大学开源软件镜像站

Arch Linux 中文社区仓库 是由 Arch Linux 中文社区驱动的非官方用户仓库。包含中文用户常用软件、工具、字体/美化包等。

完整的包信息列表(包名称/架构/维护者/状态)请 点击这里 查看。

使用方法:在 /etc/pacman.conf 文件末尾添加以下两行:

1
2
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch

之后安装 archlinuxcn-keyring 包导入 GPG key。

1
sudo pacman -Sy archlinuxcn-keyring

CentOS

镜像源:清华大学开源软件镜像站

清华大学开源软件镜像站针对不同的 CentOS 版本提供了不同的镜像源,这里仅以 CentOS 7 为例

首先备份 CentOS-Base.repo

1
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

之后启用 TUNA 软件仓库, 将以下内容写入 /etc/yum.repos.d/CentOS-Base.repo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

更新软件包缓存

1
sudo yum makecache

Debian

镜像源:清华大学开源软件镜像站

清华大学开源软件镜像站针对不同的 Debian 版本提供了不同的镜像源,这里仅以 Debian stretch 为例

备份 /etc/apt/sources.list

1
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak

然后将 /etc/apt/sources.list 替换为下面内容:

1
2
3
4
5
6
7
8
9
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security stretch/updates main contrib non-free

如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:

1
sudo apt install apt-transport-https

Fedora

镜像源:清华大学开源软件镜像站

Fedora 默认使用 Metalink 给出推荐的镜像列表,保证用户使用的镜像仓库足够新,并且能够尽快拿到安全更新,从而提供更好的安全性。所以通常情况下使用默认配置即可,无需更改配置文件。

由于 Metalink 需要从国外的 Fedora 项目服务器上获取元信息,所以对于校园内网、无国外访问等特殊情况,metalink 并不适用,此时可以如下修改配置文件。

Fedora 的软件源配置文件可以有多个,其中: 系统默认的 fedora 仓库配置文件为 /etc/yum.repos.d/fedora.repo,系统默认的 updates 仓库配置文件为 /etc/yum.repos.d/fedora-updates.repo 。将上述两个文件先做个备份,根据 Fedora 系统版本分别替换为下面内容,之后通过 sudo dnf makecache 命令更新本地缓存,即可使用 TUNA 的软件源镜像。

Fedora 27 或更旧版本

fedora 仓库 (/etc/yum.repos.d/fedora.repo)

1
2
3
4
5
6
7
8
9
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/
enabled=1
metadata_expire=28d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

updates 仓库 (/etc/yum.repos.d/fedora-updates.repo)

1
2
3
4
5
6
7
8
9
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

Fedora 28 或更新版本

fedora 仓库 (/etc/yum.repos.d/fedora.repo)

1
2
3
4
5
6
7
8
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/
metadata_expire=28d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

updates 仓库 (/etc/yum.repos.d/fedora-updates.repo)

1
2
3
4
5
6
7
8
9
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Everything/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

Homebrew

软件源:清华大学开源软件镜像站

1
2
3
4
5
6
7
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

Homebrew-bottles

1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

Termux

镜像源:清华大学开源软件镜像站

1
2
export EDITOR=vi
apt edit-sources

以 32位 ARM 平台为例,打开你常用的文本编辑器,替换成如下内容

1
2
# The termux repository mirror from TUNA:
deb [arch=all,arm] https://mirrors.tuna.tsinghua.edu.cn/termux stable main

或通过 http 访问(不建议):

1
2
# The termux repository mirror from TUNA:
deb [arch=all,arm] http://mirrors.tuna.tsinghua.edu.cn/termux stable main

如果您用的是 64位 ARM 平台,请用 aarch64 替换 arm ;如果是 Intel 平台,则用 i686 / x86_64 分别表示 32位 和 64 位。

Ubuntu

镜像源:清华大学开源软件镜像站

清华大学开源软件镜像站针对不同的 Ubuntu 版本提供了不同的镜像源,这里仅以 Ubuntu 18.04 LTS 为例

备份 /etc/apt/sources.list

1
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak

然后将 /etc/apt/sources.list 替换为下面内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

PPA

镜像源:USTC open source software mirror

修改 /etc/apt/sources.list.d 下面需要代理的仓库地址,将 ppa.launchpad.net 换成 launchpad.proxy.ustclug.org

然后更新一下软件源列表

1
sudo apt update

使用下面这个命令一键替换全部 ppa.launchpad.net 地址:

1
sudo find /etc/apt/sources.list.d/ -type f -name "*.list" -exec  sed  -i.bak -r  's#deb(-src)?\s*http(s)?://ppa.launchpad.net#deb\1 http\2://launchpad.proxy.ustclug.org#ig' {} \;

Programming language

Golang

镜像站:goproxy.io

Golang 的镜像只能在 Go module 模式中使用。

/etc/profile$HOME/.profile$HOME/.bash_profile 中添加:

1
2
export GO111MODULE=auto
export GOPROXY=https://goproxy.io

JavaScript

镜像站:TAONPM

由淘宝提供的完整 npmjs.org 镜像,你可以用此代替官方版本(只读)。

同步频率目前为 10分钟 一次,基本可以保证与官方服务同步。

替换 npm 镜像为 TAONPM:

1
npm config set registry https://registry.npm.taobao.org

如果你不想替换 npm 的官方源,可以安装 cnpm:

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

然后通过 cnpm 使用 TAONPM:

1
cnpm install [name]

Python

镜像站:清华大学开源软件镜像站

pypi 镜像每 5 分钟同步一次。

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

1
2
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

Ruby

镜像源:Ruby China

1
2
3
4
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.com
# 确保只有 gems.ruby-china.com

如果你使用 Gemfile 和 Bundler (例如:Rails 项目)

你可以用 Bundler 的 Gem 源代码镜像命令

1
bundle config mirror.https://rubygems.org https://gems.ruby-china.com

这样你不用改你的 Gemfile 的 source。

1
2
3
source 'https://rubygems.org/'
gem 'rails', '4.2.5'
...

SSL 证书错误

正常情况下,你是不会遇到 SSL 证书错误的,除非你的 Ruby 安装方式不正确。

如果遇到 SSL 证书问题,你又无法解决,请修改 ~/.gemrc 文件,增加 ssl_verify_mode: 0 配置,以便于 RubyGems 可以忽略 SSL 证书错误。

1
2
3
4
---
:sources:
- https://gems.ruby-china.com
:ssl_verify_mode: 0

如果你在意 Gem 下载的安全问题,请正确安装 Ruby、OpenSSL,建议部署 Linux 服务器的时候采用 这个 RVM 安装脚本 的方式安装 Ruby。

Rust

Cargo

镜像源:USTC open source software mirror

$HOME/.cargo/config 中添加如下内容

1
2
[registry]
index = "git://mirrors.ustc.edu.cn/crates.io-index"

如果所处的环境中不允许使用 git 协议, 可以把上述地址改为

1
index = "https://mirrors.ustc.edu.cn/crates.io-index"

同步频率为每两个小时更新一次.

如果 cargo 版本为 0.13.0 或以上, 需要更改 $HOME/.cargo/config 为以下内容:

1
2
3
4
5
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

rustup

/etc/profile$HOME/.profile$HOME/.bash_profile 中添加:

1
2
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

Mogeko
作者
Mogeko
I am a student of Debrecen University, Hungary, majoring in Computer Science. I hope to be a Full-stack in the future.