Getting git, npm and pip working behind a proxy is a common chore on locked-down networks, in CI runners, or when you need a package mirror to see you from a specific country. All three can use HTTP_PROXY environment variables, but each also has its own config that overrides them, and each has a quirk. Here are the commands for each tool, how to undo them, and the problems you'll likely hit.
Option 1: Environment Variables for All Three
export HTTP_PROXY='http://USERNAME:[email protected]:8080'
export HTTPS_PROXY="$HTTP_PROXY"
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTP_PROXY"
export NO_PROXY='localhost,127.0.0.1,.internal.example.com'git, pip and npm all honour these for HTTPS traffic. Setting both cases covers tools that read only one. This is the best choice for CI jobs and containers, because nothing is written to disk. On Windows use setx or $env:HTTPS_PROXY in PowerShell.
Git Behind a Proxy
git config --global http.proxy http://USERNAME:[email protected]:8080
# check
git config --global --get http.proxy
# remove
git config --global --unset http.proxyhttp.proxy covers both http:// and https:// remotes. To proxy only one host, for example GitHub, scope it with a URL:
git config --global http.https://github.com.proxy http://USERNAME:[email protected]:8080Two Git quirks to know. First, http.proxy doesn't apply to SSH remotes ([email protected]:...). SSH traffic needs a ProxyCommand in ~/.ssh/config, or switch the remote to HTTPS. Second, Git stores the setting in plain text in ~/.gitconfig, so anyone who can read your home directory sees the password. Prefer environment variables on shared machines.
npm Behind a Proxy
npm config set proxy http://USERNAME:[email protected]:8080
npm config set https-proxy http://USERNAME:[email protected]:8080
npm config get https-proxy
# remove
npm config delete proxy
npm config delete https-proxyNote https-proxy still uses an http:// URL; that's the proxy's own protocol, not the registry's. The settings go into ~/.npmrc. Yarn and pnpm read the same .npmrc keys in most setups, and also respect HTTPS_PROXY. If the registry is internal, add it to noproxy with npm config set noproxy 'registry.internal.example.com'.
pip Behind a Proxy
For a single install:
pip install --proxy http://USERNAME:[email protected]:8080 requestsTo make it permanent, add it to pip's config file (~/.config/pip/pip.conf on Linux, ~/Library/Application Support/pip/pip.conf on macOS, %APPDATA%\pip\pip.ini on Windows):
[global]
proxy = http://USERNAME:[email protected]:8080Or use the CLI: pip config set global.proxy http://USERNAME:[email protected]:8080. Remove it with pip config unset global.proxy.
Special Characters in the Password
All three tools take the proxy as a URL, so a password with @, :, / or # breaks parsing. Percent-encode them: @ is %40, : is %3A, / is %2F, # is %23. A quick way to encode in Python:
python3 -c "import urllib.parse; print(urllib.parse.quote('p@ss:word', safe=''))"Or use the proxy format converter to produce the URL form from host, port, username and password.
Rotating IPs and Long Installs
A big npm install or pip install makes hundreds of requests. Rotating IPs per request is fine for public registries, but some corporate mirrors or rate-limited endpoints behave better with a stable source. If you see intermittent 403s or auth issues mid-install, add a sticky session to the username, for example USERNAME-country-us-session-ci42-time-30.
Watch the Bandwidth
Package downloads add up. A fresh node_modules for a mid-sized project can be hundreds of megabytes, and ML wheels for pip can be several gigabytes. With per-GB billing, cache aggressively: keep pip's cache and npm's cache between CI runs, and only route through the proxy what needs it. For heavy, non-sensitive traffic like this, datacenter proxies cost less per GB than residential.
Troubleshooting
- Git: "Received HTTP code 407 from proxy after CONNECT": wrong credentials or inactive plan. See how to fix proxy error 407.
- npm: ECONNRESET or ETIMEDOUT: often a wrong https-proxy URL or a stale old setting. Run npm config list to see everything.
- pip: "ProxyError('Cannot connect to proxy.')": host or port wrong, or the password needs encoding.
- Anything: 402 means the plan is out of bandwidth.
Using a Proxy Only in CI
Often you only need the proxy in automated jobs, for example to install packages from a runner whose network is restricted. Keep the full proxy URL in your CI's secret store and expose it as environment variables for that job only. In a GitHub Actions workflow it looks like this:
jobs:
build:
runs-on: ubuntu-latest
env:
HTTPS_PROXY: ${{ secrets.PROXY_URL }}
HTTP_PROXY: ${{ secrets.PROXY_URL }}
NO_PROXY: localhost,127.0.0.1
steps:
- uses: actions/checkout@v4
- run: pip install -r requirements.txt
- run: npm ciNo config files are written, nothing leaks into the repository, and git, pip and npm all pick the variables up.
Using NodeProxies with Developer Tools
Use http://USERNAME:[email protected]:8080 in any of the configs above. The Docker proxy settings guide covers containers and builds. Pay as you go with no subscription; register and see pricing.
FAQ
How do I set a proxy for git clone?
Run git config --global http.proxy http://user:pass@host:port, or set HTTPS_PROXY. It works for HTTPS remotes, not SSH.
Why does npm ignore my proxy?
An older proxy or https-proxy value in ~/.npmrc or a project .npmrc may override it. Check npm config list.
Where does pip store its proxy setting?
In pip.conf (pip.ini on Windows) under [global]. pip config list shows which file is in use.
