Skip to main content

国内各种软件源镜像汇总

· 3 min read

假如你没有代理,或者代理有流量限制,那配置国内的镜像源就很有必要了,节省很多下载时间。

2024年10月2日 更新:使用 chsrc 命令配置国内镜像源。

npm

npm config set registry https://registry.npmmirror.com

yarn

yarn config set registry https://registry.npmmirror.com

electron

export ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"

brew

清华大学的帮助文档

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

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

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

二进制预编译包

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles

恢复:

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

dart & flutter

清华大学的Flutter 镜像帮助文档

pub getflutter packages get

export FLUTTER_STORAGE_BASE_URL="https://mirrors.tuna.tsinghua.edu.cn/flutter"
export PUB_HOSTED_URL="https://mirrors.tuna.tsinghua.edu.cn/dart-pub"

CocoaPods

CocoaPods 镜像使用帮助

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'

pip

设置全局

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

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

maven

mvn -v 可以查看到 maven home 的目录

Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/Cellar/maven/3.6.1/libexec

配置文件就是 Maven home 目录下的conf/setting.xml文件。

设置阿里镜像

setting.xml里面的mirrors增加阿里镜像

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

gradle

本地项目

build.gradle里面的两个repositories增加阿里地址

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

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

全局项目

~/.gradle/下创建init.gradle文件:

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

ruby

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