包管理器 | 适用语言 | 主配置文件路径 | 官方首页 |
---|---|---|---|
pip | Python | ~/.config/pip/pip.conf | pypi.org |
npm | NodeJs | ~/.npmrc | www.npmjs.com |
yarn | NodeJs | ~/.yarnrc | yarnpkg.com |
maven | Java | ~/.m2/settings.xml | maven.apache.org |
gradle | Java | ${ProjectPath}/build.gradle | gradle.org |
go | Go | ~/.config/go/env | golang.google.cn |
docker | Go | /etc/docker/daemon.json | www.docker.com |
pip
使用pip config命令
配置国内代理:
# 设置index-url
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
# 设置trusted-host
pip config set global.trusted-host mirrors.aliyun.com
# 设置timeout
pip config set global.timeout 60
# 查看所有配置
pip config list
编辑pip.conf文件
vim ~/.config/pip/pip.conf
[global]
timeout = 60
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
tips1: 编辑
~/.config/pip/pip.conf
文件与pip config
命令等效
tips2: 也可以编辑
~/.pip/pip.conf
文件修改配置,但它的优先级要小于~/.config/pip/pip.conf
npm
使用npm config命令
配置国内代理:
# 设置registry
npm config set registry https://registry.npmmirror.com
# 设置disturl
npm config set disturl https://npmmirror.com/mirrors/node
# 查看所有配置
npm config list
配置包路径:
npm config set prefix ${HOME}/.npm/usr
npm config get prefix
npm root -g
编辑.npmrc文件
vim ~/.npmrc
registry=https://registry.npmmirror.com
disturl=https://npmmirror.com/mirrors/node
yarn
使用yarn config命令
配置国内代理:
# 设置registry
yarn config set registry https://registry.npmmirror.com --global
# 设置disturl
yarn config set disturl https://npmmirror.com/mirrors/node --global
# 查看所有配置
yarn config list
编辑.yarnrc文件
vim ~/.yarnrc
registry "https://registry.npmmirror.com"
disturl "https://npmmirror.com/mirrors/node"
maven
编辑settings.xml文件
配置国内代理与包路径:
vim ~/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<localRepository>~/.m2/repository</localRepository>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus-aliyun</id>
<url>https://maven.aliyun.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-aliyun</id>
<url>https://maven.aliyun.com/repository/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
gradle
编辑build.gradle文件
配置国内代理:
适用于Gradle Groovy
vim ${ProjectPath}/build.gradle
repositories {
maven {url 'https://maven.aliyun.com/repository/public'}
}
编辑build.gradle.kts文件
适用于Gradle Kotlin
vim ${ProjectPath}/build.gradle.kts
repositories {
maven ("https://maven.aliyun.com/repository/public")
maven ("https://maven.aliyun.com/repository/google")
maven ("https://maven.aliyun.com/repository/gradle-plugin")
}
go
使用go env命令
配置国内代理:
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
配置包路径:
go env -w GOPATH=${HOME}/.go
go env
编辑env文件
vim ~/.config/go/env
GO111MODULE=on
GOPROXY=https://goproxy.cn,direct
docker
编辑daemon.json文件
配置国内代理与包路径:
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://cydedph3.mirror.aliyuncs.com"
],
"data-root": "/data/var/lib/docker"
}