记录一下如何在命令行使用代理

在windows系统设置下的代理服务器设置可以设置操作系统级别的代理,但并不会在命令行中生效。

记录一下命令行下的常用命令要怎样使用代理:

通用

关于是否使用代理,民间有一个约定:环境变量HTTP_RPOXYHTTPS_PROXYNO_PROXY

但它还不是标准,所以并不是所有的命令行工具都支持。

powershell

1
2
$env:http_proxy="http://127.0.0.1:10809"
$env:https_proxy="http://127.0.0.1:10809"

linux bash

1
2
export http_proxy="http://127.0.0.1:10809"
export https_proxy="http://127.0.0.1:10809"

npmyarn

使用代理

1
2
npm config set proxy http://127.0.0.1:10809
yarn config set https_proxy http://127.0.0.1:10809

关闭代理

1
2
yarn config delete proxy
npm config delete https_proxy

pip

1
pip install --proxy http://127.0.0.1:10809 -r requirements.txt

curlInvoke-WebRequest

1
2
3
curl -x http://127.0.0.1:10809 https://google.com

Invoke-WebRequest -Uri https://google.com -Proxy http://127.0.0.1:10809

git

使用代理

1
git config --global http.proxy http://127.0.0.1:10809

关闭代理

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