惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
Vercel News
Vercel News
Recent Announcements
Recent Announcements
B
Blog RSS Feed
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
D
Docker
Jina AI
Jina AI
IT之家
IT之家
人人都是产品经理
人人都是产品经理
L
LangChain Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog

Dejavu's Blog

甲骨文 ARM 实例部署 Gemma 4 模型 Headscale + Tailscale 组建虚拟专用网 在 Linux 上使用 Yubikey OpenPGP 应用 BuyVM VPS 块存储挂载教程 Alpine Linux 服务器配置指南 Alpine Linux 安装 Cloudflared Docker 多容器共享中心数据库 安装 Komari 服务器监控工具 Scaleway VPS 安装 Debian Linux Debian 13 下部署 AsmBB 论坛 使用 Kopia 自动化备份服务器数据 给 Docker 启用 IPv6 支持 Netcup 服务器安装自定义 ISO 镜像 烽火 HG5582A 光猫开启桥接模式 Docker 自托管 Shlink 短链服务 部署 Obsidian LiveSync 实时同步服务指南 我的 2025 年不完全回顾 Linux 下 Intel 核显驱动配置与硬件加速 Fedora Linux 安装配置记录 2025 年优雅地自托管 RSS 服务 Woodpecker CI 和 Gitea 实现 Hugo 自动部署 Gitea/Forgejo 集成 Woodpecker CI/CD 在 Blinko 中使用 Ollama 作为 AI 供应商 Docker 部署 Gitea/Forgejo Plausible CE 启用城市级地理位置识别 Blinko 开源 AI 知识库 Docker 部署指南 Netcup 免税账号注册及购买服务器全记录 Docker 自托管 Cloudreve Pro 私有网盘服务 GiffGaff SIM 卡使用体验和注意事项 简体中文互联网在变得糟糕吗?
使用本地代理给 Git 和 NPM 加速
Dejavu Moe · 2021-06-12 · via Dejavu's Blog

由于国内特殊的网络环境,Git ( 此处一般指通过 Git 连接 GitHub )、NPM 包管理器在国内使用起来可能不是那么容易,经常出现网络抽风的情况。如果您有本地代理工具,可以为它们配置本地代理。

查看端口

常用的代理软件一般都很容易看到本地 HTTP 代理和 Socks5 代理端口,此处以 Windows 下最好用的 Clash For Windows( 以下简称 CFW )为例。

查看 CFW 端口

老版本的 CFW 使用的 HTTP 端口和 Socks5 端口是不同的,但是在新版本中开始使用 Mixed Port ( 混合端口 ),因此此处都是本地端口 7890 ,一切以实际为准

Git 同时支持 HTTP 代理和 Socks5 代理,二选一即可

# http
git config --global http.proxy http://server:port
git config --global https.proxy http://server:port
# socks5
git config --global http.proxy socks5://127.0.0.1:7891
git config --global https.proxy socks5://127.0.0.1:7891

以 CFW 代理工具为例:

# http
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# socks5
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

取消 Git 代理:

git config --global --unset http.proxy
git config --global --unset https.proxy

配置 NPM 代理

NPM 原生支持 HTTP 代理类型,但是不支持 Socks5 代理类型,如果还想要使用 Socks5 代理,可能还需要使用一个工具使用 HTTP 监听 Socks5 代理 (禁止套娃),此处不做讨论

# http
npm config set proxy http://server:port
npm config set https-proxy http://server:port

以 CFW 代理工具为例:

npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890

取消 NPM 代理:

npm config delete proxy
npm config delete https-proxy

配置 Yarn 代理

Yarn 原生就拥有比 NPM 更快的速度,类似 NPM,使用 HTTP 代理(必要的话),打开终端:

# http
yarn config set proxy http://server:port
yarn config set https-proxy http://server:port

以 CFW 代理工具为例:

yarn config set proxy http://127.0.0.1:7890
yarn config set https-proxy http://127.0.0.1:7890

取消 Yarn 代理:

yarn config delete proxy
yarn config delete https-proxy