Gradle,Maven,Homebrew,npm,Ruby,Docker,pip设置国内镜像加速

  1. 1. Gradle
  2. 2. Maven
  3. 3. Homebrew
  4. 4. npm
  5. 5. Ruby
  6. 6. Docker
    1. 6.1. pip

修改镜像的目的,不是为了简单的突破封锁,而是获得更快的下载速度。千万注意根据个人实际需要修改相应路径。

Gradle

Gradle的初始化脚本(Initialization Scripts),也是运行时的全局配置。
更详细的介绍请参阅 http://gradle.org/docs/current/userguide/init_scripts.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
touch ~/.gradle/init.gradle

allprojects {
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository && repo.url != null) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
maven {
url REPOSITORY_URL
}
}
}

Maven

修改maven根目录下的conf文件夹中的settings.xml文件(或者~/.m2目录下的’settings.xml’文件)。

ps.如果你和我一样在使用idea,那么在项目右键,依次选择”Maven”-“create ‘settings.xml’”,和在~/.m2目录下新建’settings.xml’文件是一样的。

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>

Homebrew

https://brew.sh/index_zh-cn

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Homebrew-bottles 镜像

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

npm

下载地址:https://nodejs.org/en/

1
2
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist --global

配置后可通过下面方式来验证是否成功

1
npm config get

Ruby

1
2
3
4
5
6
7
8
9
10
11
#修改源
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/

# 查看镜像

gem sources -l

# 更新升级

sudo gem update --system

Docker

http://docker-cn.com/registry-mirror

修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值。

1
2
3
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

pip

临时使用,可以在使用pip的时候加参数

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

永久修改,一劳永逸:

Linux下,修改或创建 ~/.pip/pip.conf

Windows下,修改或创建 %APPDATA%\pip\pip.ini

内容如下:

1
2
3
4
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com