跳转至主要内容
日常网络报错与故障排查篇 • 更新于 2027-01

如何为终端命令行(Terminal / CMD / Git / PowerShell)配置 Clash 代理?

开发者必看:一键配置 Git clone、NPM、pip、Docker 及终端全局走 Clash 代理的标准命令。

#终端代理 #Git加速 #PowerShell #CMD配置

程序员在终端执行 git clone、npm install、pip install 或 docker pull 时,命令行默认不会走系统代理。

方案一:为 Git 单独配置 Clash 代理(最常用)

Clash 本地默认监听 HTTP 端口为 7890,在终端运行以下命令即可:

# 开启 Git 走本地 Clash 代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

# 需要关闭 Git 代理时执行:
git config --global --unset http.proxy
git config --global --unset https.proxy

方案二:PowerShell / Bash 临时全局代理

在当前终端窗口中临时注入环境变量(关闭终端后自动失效):

# Windows PowerShell 执行:
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"
# macOS / Linux Terminal 执行:
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

方案三:一劳永逸开启 TUN 模式(强烈推荐)

只要在 Clash Verge Rev 中开启 TUN 模式,全电脑底层全部终端命令、IDE 插件无序任何手动配置,自动获得全局极速加速!

📌 相关疑难解答推荐