假如你没有代理,或者代理有流量限制,那配置国内的镜像源就很有必要了,节省很多下载时间。
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.gitgit -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.gitgit -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.gitbrew 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.gitgit -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.gitgit -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.gitbrew update
dart & flutter
清华大学的Flutter 镜像帮助文档
pub get 或 flutter 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/repospod repo remove mastergit 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增加阿里镜像:
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 -lhttps://gems.ruby-china.com## 确保只有 gems.ruby-china.com