| Tested on | Ubuntu 26.04 LTS (Resolute Raccoon) |
|---|---|
| Package | curl |
| Applies to | Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, elementary OS, Zorin OS, Parrot OS, MX Linux, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora, Arch Linux |
| Privilege | read-only (no elevated privileges) |
| Scope | Learn how to configure http_proxy, https_proxy and no_proxy environment variables in Linux temporarily, permanently, system-wide, and for tools like curl, wget, apt, git and Docker. |
| Related guides | curl wget How to set up http or https proxy with special characters in username and password where to set environment variables in Linux fix curl SSL certificate problem behind corporate proxy |
Behind a corporate or campus firewall, many Linux tools reach the internet only through an HTTP proxy. Exporting http_proxy, https_proxy, and no_proxy is the fastest way to make command-line programs — curl, wget, apt, git, and others — use that path without editing each tool separately.
This guide walks through temporary and permanent setup, lowercase vs uppercase variable names, authenticated URLs, no_proxy bypass lists, and per-tool configuration when environment variables are not enough.
What is a proxy server?
A proxy sits between your machine and the internet. Your client sends the request to the proxy; the proxy forwards it and returns the response. On Linux servers and desktops, HTTP proxies are the most common type you configure with environment variables.
Common proxy categories:
- HTTP proxies — web and API traffic over HTTP/HTTPS (most corporate setups).
- SOCKS proxies — broader traffic types (mail, FTP, some apps).
- SSL proxies — TLS between client and proxy endpoint.
- Transparent proxies — caching or policy enforcement; they do not hide your origin IP.
For browser-based workflows, some teams use third-party proxy providers or fingerprint-isolated browsers paired with managed proxy endpoints. That use case is different from configuring http_proxy on a Linux shell, but the same proxy concepts apply.
Quick reference
| Variable | Typical use | Example value |
|---|---|---|
http_proxy / HTTP_PROXY |
HTTP traffic | http://proxy.example.com:8080 |
https_proxy / HTTPS_PROXY |
HTTPS (often via CONNECT) | http://proxy.example.com:8080 |
ftp_proxy / FTP_PROXY |
FTP | http://proxy.example.com:8080 |
all_proxy / ALL_PROXY |
Catch-all for schemes | http://proxy.example.com:8080 |
no_proxy / NO_PROXY |
Hosts that skip the proxy | localhost,127.0.0.1,.example.com |
For most HTTP proxy servers, both http_proxy and https_proxy use an http:// URL. See the next section on lowercase vs uppercase names before you debug a tool that “ignores” your exports.
http_proxy vs HTTP_PROXY: lowercase or uppercase?
There is no single standard. Many programs read lowercase names, many read uppercase, and some read both — but not always with the same rules.
Practical guidance:
- Set lowercase
http_proxy,https_proxy, andno_proxyfirst — they are the most widely documented. - Also set uppercase
HTTP_PROXY,HTTPS_PROXY, andNO_PROXYwhen a daemon or language runtime might only check uppercase (some Java, Node, and Python stacks do). - curl is the important exception for HTTP: it uses lowercase
http_proxyforhttp://URLs and does not useHTTP_PROXYfor HTTP because of historical CGI security concerns. It can useHTTPS_PROXYfor HTTPS URLs.
On a clean shell, exporting only http_proxy sends HTTP requests through the proxy; exporting only HTTP_PROXY may let HTTP requests go direct while HTTPS still uses HTTPS_PROXY. Always verify with curl -v when behavior looks wrong.
Check what your current session has:
env | grep -i proxy | sortSample output:
http_proxy=http://proxy.example.com:8080
https_proxy=http://proxy.example.com:8080
no_proxy=localhost,127.0.0.1Set http_proxy and https_proxy temporarily
Exports apply to the current shell and child processes. They are lost when you close the terminal unless you add them to a startup file (covered below).
Without username and password
For a typical corporate HTTP proxy, use http:// for both variables:
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"Example with a literal IP:
export http_proxy="http://192.168.1.1:8080"
export https_proxy="http://192.168.1.1:8080"Use https://proxy.example.com:port in https_proxy only when the proxy service itself accepts HTTPS connections on that port. Most HTTP proxy appliances expect http:// even when the destination site uses HTTPS.
With username and password
export http_proxy="http://username:password@proxy.example.com:8080"
export https_proxy="http://username:password@proxy.example.com:8080"With domain, username, and password
export http_proxy="http://mydomain\\user123:pass123@192.168.1.1:8080"
export https_proxy="http://mydomain\\user123:pass123@192.168.1.1:8080"Verify the exports:
echo "$http_proxy"
echo "$https_proxy"Special characters in proxy URLs
Usernames and passwords that contain @, #, $, &, or / must be URL-encoded or the shell and the URL parser will misread the string. See How to set up http or https proxy with special characters in username and password for a full walkthrough.
Common encodings:
| Character | Encoded |
|---|---|
@ |
%40 |
# |
%23 |
$ |
%24 |
: |
%3A |
/ |
%2F |
& |
%26 |
Example — password $&@pass becomes %24%26%40pass:
export http_proxy="http://user123:%24%26%40pass@192.168.1.1:8080"
export https_proxy="http://user123:%24%26%40pass@192.168.1.1:8080"Credentials in environment variables are visible to other processes on the same host (/proc/PID/environ). Prefer tool-specific credential files when your security policy requires it.
Set proxy environment variables permanently
Temporary export lines disappear after reboot. For persistence, use user-level shell startup files or system-wide files. More background on load order is in where to set environment variables in Linux.
Per user (~/.bashrc or ~/.profile)
vi ~/.bashrcAdd at the end:
export http_proxy="http://username:password@proxy.example.com:8080"
export https_proxy="http://username:password@proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,.example.com"Apply immediately:
source ~/.bashrcOn zsh, use ~/.zshrc instead. On fish: set -gx http_proxy 'http://proxy.example.com:8080'.
System-wide (/etc/environment)
/etc/environment is not a shell script — do not use export.
sudo vi /etc/environmentAdd:
http_proxy="http://username:password@proxy.example.com:8080"
https_proxy="http://username:password@proxy.example.com:8080"
no_proxy="localhost,127.0.0.1,.example.com"Log out and back in (or reboot) for login sessions to pick up changes.
System-wide login shells (/etc/profile.d/)
For scripts that run at login on many distributions:
sudo tee /etc/profile.d/proxy.sh <<'EOF'
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
export no_proxy="localhost,127.0.0.1,.example.com"
EOF
sudo chmod 644 /etc/profile.d/proxy.shBypass the proxy with no_proxy
no_proxy (and NO_PROXY) lists hosts that should connect directly. Values are usually comma-separated.
Local and loopback:
export no_proxy="localhost,127.0.0.1,::1"Internal DNS suffixes:
export no_proxy="localhost,127.0.0.1,.example.com"Private RFC1918 ranges (common in labs):
export no_proxy="10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"Wildcards and mixed lists:
export no_proxy="*.example.com,.example.org,127.0.0.0/8"no_proxy matching is not identical across every tool. Some programs support CIDR notation or * wildcards; others only match exact hostnames or domain suffixes. curl documents NO_PROXY with domain suffix, *, and CIDR support in recent versions; Docker and other clients may behave differently. Test with curl -v when in doubt.
Persist no_proxy in the same files as http_proxy (~/.bashrc, /etc/environment, or /etc/profile.d/proxy.sh).
Verify:
echo "$no_proxy"Use curl and wget with a proxy
curl
Without authentication:
curl -x http://proxy.example.com:8080 http://example.comWith authentication:
curl -U username:password -x http://proxy.example.com:8080 http://example.comWhen environment variables are set, curl picks up lowercase http_proxy / https_proxy automatically. Force a direct connection to localhost when a proxy is exported:
curl --noproxy '*' http://127.0.0.1:8080/Use curl -v to see whether traffic goes through proxy.example.com or direct.
wget
One-off proxy on the command line:
wget -e use_proxy=yes -e http_proxy=http://proxy.example.com:8080 http://example.comWith credentials in the URL:
wget -e use_proxy=yes -e http_proxy=http://user:pass@proxy.example.com:8080 http://example.comWhen http_proxy and https_proxy are exported, a plain wget http://example.com uses them. wget also reads ~/.wgetrc and /etc/wgetrc — if exports seem ignored, check for overrides there. See the GNU wget proxy manual.
Configure proxy for apt and apt-get
sudo apt update does not always inherit your user shell exports. Configure APT directly:
sudo tee /etc/apt/apt.conf.d/95proxy <<'EOF'
Acquire::http::Proxy "http://proxy.example.com:8080/";
Acquire::https::Proxy "http://proxy.example.com:8080/";
EOFAuthenticated proxy in the URL:
Acquire::http::Proxy "http://user:pass@proxy.example.com:8080/";
Acquire::https::Proxy "http://user:pass@proxy.example.com:8080/";If the proxy requires authentication and you do not want credentials inside /etc/apt/apt.conf.d/95proxy, use APT authentication configuration such as /etc/apt/auth.conf or /etc/apt/auth.conf.d/ where supported by your APT version and distribution. See Debian APT proxy configuration.
Test:
sudo apt updateRemove the file when you no longer need a proxy: sudo rm /etc/apt/apt.conf.d/95proxy.
dnf and yum (RHEL, Rocky Linux, AlmaLinux)
Add to /etc/dnf/dnf.conf:
proxy=http://proxy.example.com:8080
proxy_username=user
proxy_password=passThen run sudo dnf makecache or sudo dnf update to test.
Configure proxy for Git
Git reads http.proxy and https.proxy from configuration — independent of shell exports unless you rely on environment variables.
Set globally:
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy http://proxy.example.com:8080Unset:
git config --global --unset http.proxy
git config --global --unset https.proxyVerify:
git config --global --get http.proxyConfigure proxy for Docker containers and builds
Environment variables in your shell do not configure the Docker daemon. For client operations (pull, build), Docker reads ~/.docker/config.json:
{
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:8080",
"httpsProxy": "http://proxy.example.com:8080",
"noProxy": "localhost,127.0.0.1,.example.com"
}
}
}Create or merge that block into ~/.docker/config.json. New builds and containers started by the CLI can inherit these values.
docker pull itself fails because the Docker daemon cannot reach the registry, configure the Docker daemon proxy separately.
config.json are stored as plain text and may appear in container configuration inspect output. Use network policy and file permissions accordingly. See Docker proxy configuration.
Proxy with npm and pip
Node and Python tools often honor uppercase proxy variables:
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"
export NO_PROXY="localhost,127.0.0.1"
npm install expressFor pip:
pip install --proxy http://user:pass@proxy.example.com:8080 somepackageOr export http_proxy / https_proxy before pip install in the same shell.
Why proxy works as a normal user but not with sudo
sudo resets most environment variables unless your administrator allows them through.
Preserve your environment for one command:
sudo -E apt updateOr pass variables explicitly:
sudo env http_proxy="$http_proxy" https_proxy="$https_proxy" no_proxy="$no_proxy" apt updateFor permanent sudo access, a sysadmin can add to /etc/sudoers via visudo:
Defaults env_keep += "http_proxy https_proxy no_proxy HTTP_PROXY HTTPS_PROXY NO_PROXY"Systemd services never read your ~/.bashrc. Add Environment=http_proxy=... in a service drop-in under /etc/systemd/system/your.service.d/ when a daemon needs a proxy.
Unset or remove proxy environment variables
To remove proxy settings from the current shell:
unset http_proxy https_proxy ftp_proxy all_proxy no_proxy
unset HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXYVerify:
env | grep -i proxyIf you configured proxy permanently, also remove the entries from ~/.bashrc, ~/.profile, /etc/environment, /etc/profile.d/proxy.sh, or the tool-specific configuration file.
Troubleshooting http_proxy and https_proxy issues
| Problem | What to check |
|---|---|
| curl ignores proxy for HTTP | Use lowercase http_proxy; HTTP_PROXY alone may not affect HTTP in curl |
| curl to localhost fails | Set no_proxy=localhost,127.0.0.1 or curl --noproxy '*' |
sudo apt update ignores proxy |
Use /etc/apt/apt.conf.d/95proxy, sudo -E, or env_keep in sudoers |
| wget ignores exported vars | Check ~/.wgetrc and /etc/wgetrc for conflicting http_proxy |
| Docker build cannot reach internet | Set proxies in ~/.docker/config.json |
| Proxy works in shell but not in a service | Add Environment= to systemd unit drop-in |
407 Proxy Authentication Required |
Wrong user/password or encoding; confirm with curl -v -U user:pass -x http://proxy.example.com:8080 https://example.com |
curl: (60) SSL certificate problem: unable to get local issuer certificate |
Corporate TLS inspection without the proxy root CA in the Linux trust store |
| apt still fails with auth proxy | Use /etc/apt/auth.conf or /etc/apt/auth.conf.d/ instead of embedding secrets only in apt.conf |
Summary
You can point Linux CLI tools at an HTTP proxy by exporting http_proxy, https_proxy, and no_proxy, using http:// URLs for both HTTP and HTTPS in most corporate setups, and mirroring lowercase names with uppercase when needed. Persist values in ~/.bashrc, /etc/environment, or /etc/profile.d/. Tools such as apt, Git, and Docker often need their own configuration or sudo -E — shell exports alone are not always enough.
References
- IBM — environment variables in Unix
- curl manual — environment variables
- GNU wget — proxies
- RFC 3986 — URI encoding
- Debian wiki — APT proxy configuration
- Docker — configure proxy for the CLI
- Git — git config documentation
Frequently Asked Questions
1. What is the difference between http_proxy and HTTP_PROXY?
2. Should https_proxy use http:// or https:// in the URL?
http://proxy.example.com:port. HTTPS sites are tunneled with HTTP CONNECT through that proxy. Use https:// in the variable only when the proxy service itself listens with TLS.3. Why does sudo apt update ignore my proxy?
4. How do I bypass the proxy for localhost and internal hosts?
5. How do I set a proxy for Git only?
git config --global http.proxy http://proxy.example.com:8080 and the same for https.proxy. Unset with git config --global --unset http.proxy when you no longer need it.
