如果你的包管理器想直接使用优秀的镜像仓库,请参考这个:Thanks-Mirror

pip

~/.config/pip/pip.conf

[global]
proxy=http://localhost:1087

注意不支持 socks5。

git

clone with ssh

在 文件 ~/.ssh/config 后添加下面两行:

Host github.com
# Mac下
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
# Linux下
ProxyCommand nc --proxy-type socks5 --proxy 127.0.0.1:1080 %h %p

注意 Linux 和 Mac 下 ncat/netcat 区别,详见:
What are the differences between ncat, nc and netcat?

clone with http

git config --global http.proxy http://127.0.0.1:1087

建议使用 http,因为 socks5 在使用 git-lfs 时会报错。

Reference

laispace/git 设置和取消代理

cargo

Cargo 会依次检查以下位置:

  1. 环境变量 CARGO_HTTP_PROXY
export CARGO_HTTP_PROXY=http://127.0.0.1:1080
  1. 任意 config.toml 中的 http.proxy
[http]
proxy = "127.0.0.1:1080"
  1. 环境变量 HTTPS_PROXY & https_proxy & http_proxy
export https_proxy=http://127.0.0.1:1080
export http_proxy=http://127.0.0.1:1080

http_proxy 一般来讲没必要,除非使用基于 HTTP 的 Crate Repository。

Cargo 使用 libcurl,故可接受任何符合 libcurl format 的地址与协议。

( 127.0.0.1:1080 , http://127.0.0.1:1080, socks5://127.0.0.1:1080 )均可

Reference

The Cargo Book - httpproxy

apt

/etc/apt/apt.conf.d/ 目录下新增 proxy.conf 文件,加入:

Acquire::http::Proxy "http://127.0.0.1:8080/";
Acquire::https::Proxy "http://127.0.0.1:8080/";

如果希望使用 Socks5 代理,则加入:

Acquire::http::Proxy "socks5h://127.0.0.1:8080/";
Acquire::https::Proxy "socks5h://127.0.0.1:8080/";

Reference

curl

添加至 ~/.curlrc

socks5 = "127.0.0.1:1080"

gradle

添加至 ~/.gradle/gradle.properties

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1087
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1087

Reference

Gradle proxy configuration

Maven

添加至 %Maven 安装目录%/conf/settings.xml

<proxies>
<proxy>
<id>proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>127.0.0.1</host>
<port>1087</port>
</proxy>
</proxies>

Reference

Guide-proxies

go

HTTP_PROXY=socks5://localhost:1080 go get

测试了下 HTTPS_PROXY和 ALL_PROXY 都不起作用,或可使用:goproxy.io

npm

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

用 socks5 就报错。
推荐使用 yarn,npm 是真的慢。

reference

rustup

export https_proxy=http://127.0.0.1:1080

yarn

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

不支持 socks5。

Reference

yarn需要像npm一样配置代理么?

yarn2

Yarn 2+ - Official

yarn config set httpProxy http://127.0.0.1:1087
yarn config set httpsProxy http://127.0.0.1:1087

不支持全局设置,支持 socks5。

提示: 这个命令会修改项目目录下的 .yarnrc.yml 文件, 请留意不要把带有如

httpsProxy: "socks5://127.0.0.1:1080"

的代码提交到仓库, 以免造成麻烦。

建议使用 npm 镜像而不是配置使用代理
yarn config set npmRegistryServer https://127.0.0.1:1087

注意: 此方法不适用于下载 yarn 官方插件!

yarn 的官方插件默认会从 GitHub(raw.githubusercontent.com) 上下载,您可能依旧需要配置代理。

Reference

gem

添加至 ~/.gemrc

---
# See 'gem help env' for additional options.
http_proxy: http://localhost:1087

brew

设置环境变量:

ALL_PROXY=socks5://localhost:1080

wget

添加至 ~/.wgetrc

use_proxy=yes
http_proxy=127.0.0.1:1087
https_proxy=127.0.0.1:1087

Reference

How to set proxy for wget?

snap

sudo snap set system proxy.http="http://127.0.0.1:1087"
sudo snap set system proxy.https="http://127.0.0.1:1087"

Reference

How to install snap packages behind web proxy

docker

$ sudo mkdir -p /etc/systemd/system/docker.service.d
$ sudo vim /etc/systemd/system/docker.service.d/proxy.conf

[Service]
Environment="ALL_PROXY=socks5://localhost:1080"

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

必须是 socks5,http 不生效

electron

设置环境变量:

ELECTRON_GET_USE_PROXY=true
GLOBAL_AGENT_HTTPS_PROXY=http://localhost:1080

References

wsl2

WSL2 环境下可以通过设置 ~/.vscode-server/server-env-setup 脚本文件,设置开发环境的环境变量,使用代理。

WSL2 内环境访问 Win 下的代理程序端口代理(例子代码中 http 代理端口监听 17070),因为子网地址每次启动都不一样,需要动态处理。

新建 ~/.vscode-server/server-env-setup 文件,该文件会在 VSCode 启动 WSL 环境后被 source

WSL_HOST=$(sed -n '/^nameserver/p' /etc/resolv.conf | cut -d' ' -f2)
export http_proxy=http://${WSL_HOST}:17070
export https_proxy=$http_proxy
export all_proxy=$http_proxy

References

Developing in WSL

ssh

VSCode SSH 后的环境不会使用本地界面 VSCode 内的代理设置,如果 SSH 主机没有默认网络链接或在墙内,会导致问题。

SSH 主机无网络

需要手动下载 vscode 的 server 端传输部署,详情见链接:

SSH 主机在墙内

虽然文档未提及,但是可以使用 WSL 模式的方案。

SSH 主机有代理程序监听在 17070 端口:

新建 ~/.vscode-server/server-env-setup 文件,该文件会在 VSCode 启动 WSL 环境后被 source

export http_proxy=http://127.0.0.1:17070
export https_proxy=$http_proxy
export all_proxy=$http_proxy

References

Remote Development using SSH

scoop

scoop config proxy 127.0.0.1:1080

Reference

Using Scoop behind a proxy

评论