Set Proxy Environment Variables for the Terminal
Route command-line tools like curl, wget, git, and pip through an HTTP or SOCKS proxy using http_proxy, https_proxy, and all_proxy.
Export http_proxy and https_proxy to your proxy address, e.g. export https_proxy=http://127.0.0.1:7890, then run your commands as usual.
01Command
Command
$ export http_proxy=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:789002What it does
Most command-line programs read the http_proxy, https_proxy, and all_proxy environment variables, so exporting them once makes the whole shell session go through your proxy — useful when a corporate network requires it or when you run a local client like Clash or v2ray. Use http:// for an HTTP proxy port and socks5:// for a SOCKS proxy in all_proxy. The setting only lives in the current terminal; add the export line to ~/.bashrc or ~/.zshrc to make it permanent, and use unset to go back to a direct connection.
03Risk
!Warning: A proxy set this way is not encrypted or audited — make sure you trust the proxy host, and remember sudo commands may not inherit these variables unless you configure sudo's env_keep.
04Undo
Undo
$ unset http_proxy https_proxy all_proxy05Sources
- Proxy server — Environment variablesEvidence: Explains the http_proxy, https_proxy and all_proxy environment variables used by most command-line tools to route traffic through a proxy.
- curl man page — proxy environment variablesEvidence: Documents that curl reads the http_proxy, HTTPS_PROXY and ALL_PROXY environment variables when no explicit --proxy option is given.
Last verified: 2026-09-18 · Category: Network