三种方式

1. 临时生效(仅当前终端)

export http_proxy=http://proxyAddress:port
export https_proxy=http://proxyAddress:port

关闭终端后失效,不影响系统设置。适合偶尔使用。

2. 永久生效(写入 Shell 配置)

~/.bashrc 末尾添加:

http_proxy=http://proxyAddress:port
https_proxy=http://proxyAddress:port
export http_proxy https_proxy

然后执行 source ~/.bashrc 生效。

3. 仅对特定工具生效

apt:

sudo vi /etc/apt/apt.conf
# 添加:
Acquire::http::Proxy "http://proxyAddress:port";
Acquire::https::Proxy "http://proxyAddress:port";

git:

git config --global http.proxy http://proxyAddress:port

wget:

# 编辑 ~/.wgetrc
use_proxy = on
http_proxy = http://proxyAddress:port
https_proxy = http://proxyAddress:port

带认证的代理

如果代理需要用户名和密码:

export http_proxy=http://userName:password@proxyAddress:port
export https_proxy=http://userName:password@proxyAddress:port

取消代理

unset http_proxy https_proxy