本页面记录我们团队开发环境中的使用国内镜像站加速的配置参考,便于快速配置开发环境使用的镜像站,一些相关的详细参考内容会以参考资料形式给出。
本文以全局镜像配置为主,即配置在全局的路径下,所有的项目均受影响。像 Maven, Gradle 之类的工具支持项目单独定义镜像仓库,并不在本文涉及的内容中。
镜像配置列表:
创建目录 ~/.gradle/init.d
(Unix/Linux 环境)或 %USERPROFILE%/.gradle/init.d
(Windows 环境),写入以下两个文件:
repo.gradle:
allprojects { buildscript { repositories { maven { url "https://repo.huaweicloud.com/repository/maven" } } } repositories { maven { url "https://repo.huaweicloud.com/repository/maven" } } gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } tasks.withType(GroovyCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } } }
pluginManagement.gradle (只对 Gradle 4.0
及以上版本使用新的 plugins {}
DSL 部分有效):
settingsEvaluated { settings -> settings.pluginManagement { repositories { maven { url "https://repo.huaweicloud.com/repository/maven" } gradlePluginPortal() } } }
注: gradle 使用镜像站下载依赖的时候可能会出现镜像站还未缓存完毕依赖,从而下载依赖的时候出错,导致 task 失败退出的情况。如果遇到这种情况,等待镜像站缓存完毕,加上 --refresh-dependencies
参数重新运行一次 task 即可,如:
./gradlew --refresh-dependencies build
参考资料:
创建 ~/.m2/settings.xml
(Linux/Unix 环境)或 %USERPROFILE%/.m2/settings.xml
(Windows 环境)文件,写入以下内容:
<?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>huaweicloud</id> <mirrorOf>*</mirrorOf> <url>https://repo.huaweicloud.com/repository/maven</url> </mirror> </mirrors> </settings>
参考资料:
创建 ~/.groovy/grapeConfig.xml
(Linux/Unix 环境)或 %USERPROFILE%/.groovy/grapeConfig.xml
(Windows 环境)文件,写入以下内容:
<ivysettings> <settings defaultResolver="downloadGrapes"/> <resolvers> <chain name="downloadGrapes" returnFirst="true"> <filesystem name="cachedGrapes"> <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/> <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/> </filesystem> <ibiblio name="localm2" root="${user.home.url}/.m2/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true"/> <ibiblio name="huawei" root="https://mirrors.huaweicloud.com/repository/maven" m2compatible="true"/> </chain> </resolvers> </ivysettings>
参考资料:
配置环境变量:
NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs
参考资料:
执行命令:
npm config set registry https://registry.npm.taobao.org npm config set disturl https://npm.taobao.org/dist npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs npm config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver npm config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ npm config set python_mirror https://npm.taobao.org/mirrors/python npm config set electron_builder_binaries_mirror https://npm.taobao.org/mirrors/electron-builder-binaries/ npm config set node_sqlite3_binary_host_mirror https://npm.taobao.org/mirrors
手改 ~/.npmrc
或设置等效的环境变量均有效。
参考资料:
执行命令:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
参考资料:
执行命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main conda config --set show_channel_urls yes
修改 .condarc
配置文件可以达成同样的效果,参考下方参考资料。
参考资料:
通过镜像站安装插件:
vagrant plugin install --plugin-clean-sources --plugin-source https://gems.ruby-china.com/ <plugin>...
vagrant-vbguest
下载 VBoxGuestAdditions 镜像(修改 Vagrantfile
):
config.vbguest.iso_path = "https://mirrors.tuna.tsinghua.edu.cn/virtualbox/%{version}/VBoxGuestAdditions_%{version}.iso"
通过镜像站下载 box:
# Ubuntu镜像 vagrant init ubuntu-bionic https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box # Centos镜像 vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box
也可以修改 Vagrantfile
的 config.vm.box_url = "box文件的url"
。
参考资料:
设置环境变量:
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
写入配置文件 ~/.cargo/config
:
[source.crates-io] replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index"
参考资料: