开发人员常用的国内镜像仓库

awesome-mirrors.jpg

本文如果对你有帮助请帮忙Star一下,以帮助更多的人。

由于众所周知的原因,中国的开发者在下载各种依赖的时候速度都比较慢。因此部分有实力的高校、公司在国内搭建了方便开发者的各种镜像仓库,并且几乎都是和国外的源定时同步的。本仓库主要收集方便中国开发者提速的源,以及配置的方式。

下面的操作方式在不同的系统可能会有细微的差别,欢迎大家补充和纠正。

目录

Docker

首先从网上搜索国内的docker registry源,然后修改docker的配置并重启docker。在这里我比较推荐使用免费的阿里云镜像加速器(至少截至2020年09月03日还是免费的),目前使用一直比较平稳。

  • 获取镜像加速url

注册一个阿里云账号并登录,在产品与服务中搜索容器镜像服务,跟随引导完成必要的一些步骤,然后来到这个页面,就可以看到自己专有的加速器地址了。

  • 给docker客户端配置镜像加速器

这里以MacOS为例,其他系统类似。如果没有/etc/docker/daemon.json文件,则可以直接通过下面的命令完成配置;如果该文件已经存在了,则选择自己熟悉的文本编辑器编辑该文件,添加加速器地址的配置。如果你使用的带界面的客户端,也可以在Preferences... -> Docker Engine显示的编辑器中添加相应的配置。

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}
EOF

注意:将https://xxx.mirror.aliyuncs.com替换成你自己的镜像加速器地址。再次提醒,配置完成后,重启docker之后才会生效。

除了阿里云的源,还有一些其他的源可以参考:

  1. https://registry.docker-cn.com
  2. http://hub-mirror.c.163.com
  3. http://docker.mirrors.ustc.edu.cn
  4. http://mirror.azure.cn/help/docker-registry-proxy-cache.html

Nodejs

下面是NPM的配置方式,以淘宝的源为例。

  • 临时使用
# 为单用户安装
npm install --registry https://registry.npm.taobao.org <package-name>

#为所有用户安装
npm install --global --registry https://registry.npm.taobao.org <package-name>

# yarn
yarn save <package-name> --registry https://registry.npm.taobao.org
  • 默认使用
# npm
npm set registry https://registry.npm.taobao.org

# yarn
yarn config set registry https://registry.npm.taobao.org

除了淘宝的源,还有一些其他的源可以参考:

  1. http://crproxy.trafficmanager.net:4873

另外,可以通过nrm管理多个NPM的源,相应的yarn也有yrm

Python

PyPI (Python Package Index) 是 Python 编程语言的软件存储库。开发者可以通过 PyPI 查找和安装由 Python 社区开发和共享的软件,也可以将自己开发的库上传至 PyPI 。这里以阿里云的源为例。

  • 临时使用
pip install -i https://mirrors.aliyun.com/pypi/simple <package-name>

注意,simple 不能少, 是 https 而不是 http

  • 默认使用

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

pip install pip -U
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple

除了阿里云的源,还有一些其他的源可以参考:

  1. https://pypi.tuna.tsinghua.edu.cn/simple
  2. https://pypi.mirrors.ustc.edu.cn/simple
  3. https://pypi.douban.com/simple
  4. http://mirror.azure.cn/pypi/simple

Anaconda的配置方式可以参考清华大学的Anaconda镜像使用帮助

Java

  • Maven 配置

打开 Maven 的配置文件(windows机器一般在maven安装目录的conf/settings.xml),在<mirrors></mirrors>标签中添加 mirror 子节点:

<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>

如果想使用其它代理仓库,可在<repositories></repositories>节点中加入对应的仓库使用地址。以使用spring代理仓为例:

<repository>
    <id>spring</id>
    <url>https://maven.aliyun.com/repository/spring</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
  • gradle 配置

在 build.gradle 文件中加入以下代码:

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        mavenLocal()
        mavenCentral()
    }
}

如果想使用 maven.aliyun.com 提供的其它代理仓,以使用 spring 仓为例,代码如下:

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/spring/'}
        mavenLocal()
        mavenCentral()
    }
}

除了Spring的仓库之外,阿里云还提供一些其他的源:

  1. central https://maven.aliyun.com/repository/central
  2. jcenter https://maven.aliyun.com/repository/public
  3. public https://maven.aliyun.com/repository/public
  4. google https://maven.aliyun.com/repository/google
  5. gradle-plugin https://maven.aliyun.com/repository/gradle-plugin
  6. spring https://maven.aliyun.com/repository/spring
  7. spring-plugin https://maven.aliyun.com/repository/spring-plugin
  8. grails-core https://maven.aliyun.com/repository/grails-core
  9. apache snapshots https://maven.aliyun.com/repository/apache-snapshots

Goproxy

使用go1.11以上版本并开启go module机制,下面以阿里云的源为例:

export GO111MODULE=on
export GOPROXY=https://mirrors.aliyun.com/goproxy

除了阿里云的源,还有一些其他的源可以参考:

  1. https://goproxy.cn
  2. https://goproxy.io

Ruby

这里以配置Ruby China的源为例:

gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

Bundler用户参考如下配置:

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

这样你不用改你的Gemfilesource

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

除了Ruby China的源,还有一些其他的源可以参考:

  1. https://mirrors.aliyun.com/rubygems
  2. https://mirrors.tuna.tsinghua.edu.cn/rubygems
  3. https://mirrors.ustc.edu.cn/rubygems
  4. http://mirror.azure.cn/rubygems

Alpine apk

Alpine Linux 是一个面向安全,轻量级的基于musl libc与busybox项目的Linux发行版。

下面以配置阿里云的源作为例子:

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

除了阿里云的源,还有一些其他的源可以参考:

  1. dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn

Centos yum

CentOS,是基于 Red Hat Linux 提供的可自由使用源代码的企业级 Linux 发行版本;是一个稳定,可预测,可管理和可复制的免费企业级计算平台。

更换源之前,建议先备份一下,下面以阿里云的源为例:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载阿里云的源:

# Centos 6
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
# Centos 7
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# Centos 8
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

生成缓存:

yum makecache

注意: 非阿里云ECS用户会出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com'信息,不影响使用。用户也可自行修改相关配置:

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

除了阿里云的源,还有一些其他的源可以参考:

  1. https://mirrors.tuna.tsinghua.edu.cn/help/centos
  2. http://mirrors.ustc.edu.cn/help/centos.html
  3. http://mirror.azure.cn/help/centos.html

Debian apt

Debian GNU/Linux ,是一个操作系统及自由软件的发行版,由一群自愿付出时间和精力的用户来维护并更新。它附带了超过 59000 个软件包,这些预先编译好的软件被打包成一种良好的格式以便于用户安装和使用。

下面以阿里云的源为例:

debian 7.x (wheezy)

编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)

deb http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib

debian 8.x (jessie)

编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)

deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib

debian 9.x (stretch)

编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)

deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib

除了阿里云的源,还有一些其他的源可以参考:

  1. https://mirrors.tuna.tsinghua.edu.cn/help/debian
  2. http://mirrors.ustc.edu.cn/help/debian.html

Ubuntu apt

Ubuntu,是一款基于 Debian Linux 的以桌面应用为主的操作系统,内容涵盖文字处理、电子邮件、软件开发工具和 Web 服务等,可供用户免费下载、使用和分享。

下面以阿里云的源为例:

用你熟悉的编辑器打开/etc/apt/sources.list,替换默认的http://archive.ubuntu.com/mirrors.aliyun.com

ubuntu 16.04 配置如下

deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

ubuntu 18.04(bionic) 配置如下

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

ubuntu 20.04(focal) 配置如下

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

除了阿里云的源,还有一些其他的源可以参考:

  1. https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu
  2. http://mirrors.ustc.edu.cn/help/ubuntu.html
  3. http://mirror.azure.cn/help/ubuntu.html

Homebrew

Homebrew 是一款自由及开放源代码的软件包管理系统,用以简化 macOS 系统上的软件安装过程。它拥有安装、卸载、更新、查看、搜索等很多实用的功能,通过简单的一条指令,就可以实现包管理,十分方便快捷。

下面以阿里云的源为例:

名称 说明
brew Homebrew 源代码仓库
homebrew-core Homebrew 核心源
homebrew-cask 提供 macOS 应用和大型二进制文件的安装
homebrew-bottles 预编译二进制软件包
  • Bash 终端配置
# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
  • 恢复默认配置

出于某些场景, 可能需要回退到默认配置, 你可以通过下述方式回退到默认配置。

首先执行下述命令:

# 重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
# 重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

然后删掉 HOMEBREW_BOTTLE_DOMAIN 环境变量,将你终端文件~/.bash_profileHOMEBREW_BOTTLE_DOMAIN行删掉, 并执行source ~/.bash_profile

除了阿里云的源,还有一些其他的源可以参考:

  1. https://mirrors.tuna.tsinghua.edu.cn/help/homebrew
  2. http://mirrors.ustc.edu.cn/help/brew.git.html

iOS

CocoaPods 是一个 Cocoa 和 Cocoa Touch 框架的依赖管理器,具体原理和 Homebrew 有点类似,都是从 GitHub 下载索引,然后根据索引下载依赖的源代码。

下面以清华大学的源为例:

对于旧版的 CocoaPods 可以使用如下方法使用 tuna 的镜像:

$ pod repo remove master
$ pod repo add master https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
$ pod repo update

新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

最后进入自己的工程,在自己工程的podFile第一行加上:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

注意:1.7.2开始,已经完全切到CDN上了。1.8以上甚至把CDN作为默认源使用,在Podfile最上面添加即可。

source 'https://cdn.cocoapods.org/'

除了清华大学的源,还有一些其他的源可以参考:

  1. https://gitclub.cn/CocoaPods/Specs.git
  2. http://git.oschina.net/akuandev/Specs.git
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
禁止转载,如需转载请通过简信或评论联系作者。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,902评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,037评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,978评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,867评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,763评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,104评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,565评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,236评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,379评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,313评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,363评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,034评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,637评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,719评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,952评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,371评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,948评论 2 341