【高效】开发过程中常见配置(pip、npm、maven、git等各种国内源)
·
常用开发工具国内镜像与代理配置指南
一、 前端开发工具
1. NVM (Node Version Manager)
配置文件: NVM 安装目录下的 settings.txt
在文件末尾添加以下参数:
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
2. NPM / Electron
注意: Node 16.16.0 及以上版本中,
--global参数已被废弃,建议使用--location=global。
配置文件位置:
- Windows:
%HOMEPATH%\.npmrc
一键配置命令:
# 设置 npm 全局镜像源
npm config set registry https://registry.npmmirror.com --location=global
npm config set disturl https://npmmirror.com/dist --location=global
# Electron 及其相关依赖镜像
npm config set ELECTRON_MIRROR https://npmmirror.com/mirrors/electron/ --location=global
npm config set CHROMEDRIVER_CDNURL https://npmmirror.com/mirrors/chromedriver --location=global
npm config set ELECTRON_BUILDER_BINARIES_MIRROR https://npmmirror.com/mirrors/electron-builder-binaries/ --location=global
# 验证安装
npm install electron@16.0.7
二、 后端、包管理与环境
1. Pip (Python)
配置文件位置:
- Linux:
~/.pip/pip.conf - Windows:
%HOMEPATH%\pip\pip.ini
配置内容:
[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple
2. Maven (Java)
配置文件位置: %HOMEPATH%\.m2\settings.xml
在 <mirrors> 标签内添加:
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
3. Homebrew (macOS)
将 Homebrew 核心源及二进制预编译包(Bottles)替换为阿里源。
# 1. 修改 brew.git 为阿里源
git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 2. 修改 homebrew-core.git 为阿里源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 3. 替换 Homebrew Bottles 镜像
# 如果使用 zsh (默认):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
# 如果使用 bash:
# echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
# source ~/.bash_profile
# 4. 刷新源
brew update
三、 版本控制 (Git / GitHub)
1. Git 基础信息与多平台免密登录
通过配置 _netrc 文件,可以一次性配置多个服务器,避免频繁输入密码。
⚠️ 缺点:密码以明文存储,安全性较低。
全局信息配置:
git config --global credential.helper store
git config --global user.name "你的GitHub用户名"
git config --global user.email "你的邮箱"
明文密码配置位置:
- Windows:
%HOMEPATH%\_netrc
配置内容:
machine gitee.com
login 你的Gitee用户名
password 你的Gitee密码
machine github.com
login 你的GitHub用户名
password 你的GitHub密码
2. Git 网络代理设置
用于解决 fatal: unable to connect... 或网络超时问题。
方案 A:设置本地代理(推荐)
根据你本地代理软件的协议和端口进行设置(如 1080 或 8118):
# 设置 HTTP/HTTPS 代理 (以 SOCKS5 代理为例)
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
# 设置 HTTP/HTTPS 代理 (以 HTTP 协议为例)
# git config --global http.proxy http://127.0.0.1:8118
# git config --global https.proxy https://127.0.0.1:8118
# 取消代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy # 同步清理npm代理
方案 B:使用 GitHub 国内镜像站(替代方案)
常见镜像站:gitclone.com、hub.fastgit.xyz、github.do、ghproxy.com
# 查看当前所有全局配置
git config --global --list
# 自动将 github.com 替换为镜像站下载
git config --global url."https://hub.fastgit.xyz/".insteadOf "https://github.com/"
# 自动将 git:// 协议替换为 https://
git config --global url."https://".insteadOf git://
git config protocol.https.allow always
# 取消镜像站替换
git config --global --unset url."https://hub.fastgit.xyz/".insteadOf
更多推荐


所有评论(0)