s-blog

设置终端代理

ssssmy · 2026-05-28 · 2 min · Windows

在终端中设置代理,用于访问外部网络资源。

PowerShell

# 设置代理
$Env:http_proxy="http://127.0.0.1:7890"
$Env:https_proxy="http://127.0.0.1:7890"

# 取消代理
$Env:http_proxy=""
$Env:https_proxy=""

CMD

:: 设置代理
set http_proxy=http://127.0.0.1:7890
set https_proxy=http://127.0.0.1:7890

:: 取消代理
set http_proxy=
set https_proxy=

Git 代理

# 设置 Git 代理
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

npm 代理

# 设置代理
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890

# 取消代理
npm config delete proxy
npm config delete https-proxy

永久配置(系统环境变量)

在系统环境变量中添加:

变量名
HTTP_PROXY http://127.0.0.1:7890
HTTPS_PROXY http://127.0.0.1:7890
NO_PROXY localhost,127.0.0.1,10.*

注意:端口号(7890)需要根据实际代理软件的配置修改,常见端口有 7890(Clash)、10809(V2Ray)、1080(SS)。

原文链接:https://www.ssssmy.com/notes/she-zhi-zhong-duan-dai-li