🎉 Premium Proxies · 24-Hour Free TrialClaim Now
Guides

How to Set a Proxy in the Linux Terminal (http_proxy)

Set proxy in the Linux terminal with http_proxy, https_proxy and no_proxy: which case each tool reads, why the scheme stays http://, and where to persist it.

S SparkProxy 48 18 min read
Share
How to Set a Proxy in the Linux Terminal (http_proxy)

To set proxy in the Linux terminal for curl, wget, git and your own scripts, you export four environment variables: http_proxy, https_proxy, all_proxy and no_proxy. The part that wastes an afternoon is everything around those four names. Some tools read only the lowercase spelling, https_proxy almost always needs an http:// scheme, a password with an @ in it breaks parsing, and sudo throws your exports away. This guide covers each of those with error strings we reproduced on a real Ubuntu box, then shows where to persist the settings so cron jobs and services pick them up too.

The Four Variables and What Each One Covers

The variable name selects the protocol of the target URL. The value describes how to reach the proxy. Keep those two ideas apart and most of the confusion in this topic goes away.

VariableUsed for requests toNotes
`http_proxy``http://` URLscurl reads it in lowercase only
`https_proxy``https://` URLsValue normally begins with `http://` (see below)
`all_proxy`Any protocol without its own variablecurl and git honor it; GNU Wget does not
`no_proxy`Hosts that must bypass the proxyComma-separated, suffix matching

These variables are a convention, not a kernel feature. Nothing in Linux enforces them. Each program decides whether to read them, which spelling to accept and how to parse the value, which is why the same shell can send curl through a proxy while wget goes direct.

The curl manual (curl 8.5.0 on Ubuntu 24.04, also published at curl.se/docs/manpage.html) states the general rule plainly: "The environment variables can be specified in lower case or upper case. The lower case version has precedence. http_proxy is an exception as it is only available in lower case."

Set a Proxy for the Current Terminal Session

For a quick job, export the variables in the shell you're working in. They last until you close that terminal. Using the SparkProxy gateway with user:pass authentication (port 11000 hands out a random IP per request):

export http_proxy="http://spark_user:s3cr3t%402026@gateway.sparkproxy.io:11000"
export https_proxy="$http_proxy"
export no_proxy="localhost,127.0.0.1,::1"

curl -s https://api.ipify.org

Notice %40 in the password. The real password is s3cr3t@2026, but an unencoded @ makes the parser read everything after it as the hostname. The curl manual says the user and password in a proxy string "are URL decoded by curl. This allows you to pass in special characters such as @ by using %40 or pass in a colon with %3a." Here is the encoding table you'll actually need:

Character in passwordWrite it as
`@``%40`
`:``%3A`
`/``%2F`
`#``%23`
`%``%25`
space`%20`

If you'd rather not encode by hand, let Python do it once:

python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=""))' 's3cr3t@2026'
# s3cr3t%402026

For a single command, skip export entirely and prefix the assignment. The variable then exists only for that one process:

https_proxy="http://spark_user:s3cr3t%402026@gateway.sparkproxy.io:11000" \
  wget -qO- https://api.ipify.org

To undo a session-wide setting, unset http_proxy https_proxy all_proxy no_proxy. curl's -x flag and the rest of its per-request options are covered in our cURL proxy guide, so this post sticks to the environment route that every tool on the box shares.

Free trial

Scraping at scale? Skip the blocks.

Fast, unblockable datacentre proxies with unlimited bandwidth.

Lowercase or Uppercase: What Each Tool Reads

Documentation for each tool answers this in a different place, so we tested it. Setup: Ubuntu 24.04.5 LTS under WSL2, curl 8.5.0 (OpenSSL 3.0.13), GNU Wget 1.21.4 and Python 3.12.3, all pointed at a small authenticated HTTP proxy we ran on 127.0.0.1:3128 that logs every request it receives. Each command started from an empty environment (env -i) with only one variable set, and we checked the proxy log to see whether traffic actually arrived. These are our measurements on 2026-10-30, not vendor claims.

Variable set (only this one)curl 8.5.0Wget 1.21.4Python 3.12 urllib
`http_proxy` (lowercase)UsedUsedUsed
`HTTP_PROXY` (uppercase)**Ignored, went direct****Ignored, went direct**Used
`https_proxy` (lowercase)UsedUsedUsed
`HTTPS_PROXY` (uppercase)Used**Ignored, went direct**Used
`all_proxy`Used**Ignored, went direct**Not applicable
`NO_PROXY` (uppercase)Honored**Ignored, still proxied**Not tested

The Wget column is the one that bites people. Its manual lists only http_proxy, https_proxy, ftp_proxy and no_proxy, in lowercase, and in our test every uppercase spelling was ignored without an error or a warning. With HTTPS_PROXY set, the request simply left from the machine's own IP. With NO_PROXY set, the opposite happened: traffic you meant to keep local still went through the proxy. If you set only the uppercase form because a Docker or CI guide told you to, curl will behave and Wget will quietly bypass the proxy.

curl's refusal to read uppercase HTTP_PROXY is deliberate. It dates from the httpoxy issue, where CGI servers turn an incoming Proxy: header into an HTTP_PROXY variable; the curl guide linked above explains it in detail.

When both spellings are present with different values, Python's urllib picked the lowercase one in our test. You can check what Python will see without sending a request:

import urllib.request

# Shows the proxy map Python builds from the environment.
# Lowercase variables win when both spellings are set.
proxies = urllib.request.getproxies()
for scheme, url in sorted(proxies.items()):
    print(f"{scheme:6} -> {url}")

bypass = proxies.get("no", "")
print("no_proxy:", bypass or "(not set)")

The practical rule: set both cases to the same value, lowercase first. It costs two extra lines and removes a whole class of "works in curl, not in my script" bugs.

for v in http_proxy https_proxy no_proxy; do
  export "${v^^}=${!v}"   # copy each lowercase value to its uppercase twin
done
env | grep -i _proxy

Why https_proxy Still Starts With http://

This is the most common misconfiguration we see: https_proxy=https://.... It looks logical, but the scheme in the value describes the connection from your machine to the proxy, not to the website.

With an ordinary forward proxy, the client opens a plain TCP connection to the proxy and sends CONNECT api.ipify.org:443. The proxy replies 200 Connection established, and only then does your client start TLS with the real site, end to end through the tunnel. The proxy never sees inside the HTTPS session. That first hop is plain HTTP, so the correct value is http://.

Write https:// instead and curl tries to open TLS to the proxy itself. The curl manual confirms the meaning: "HTTPS proxy support works set with the https:// protocol prefix for OpenSSL and GnuTLS (added in 7.52.0)." Against a proxy that only speaks plain HTTP on that port, our test produced:

$ https_proxy=https://labuser:p%40ss%3Aw0rd@127.0.0.1:3128 curl -sS https://api.ipify.org
curl: (35) OpenSSL/3.0.13: error:0A00010B:SSL routines::wrong version number

"Wrong version number" means OpenSSL sent a TLS ClientHello and got back plain-text HTTP bytes. Change the scheme to http:// and the same command returns an IP.

Wget behaved differently, and in a way that hides the mistake. Given the same https:// proxy URL, Wget 1.21.4 connected in plain text, issued CONNECT, and the download succeeded. So a value that works in Wget can fail in curl, git and Python on the same machine. Don't treat "wget works" as proof the variable is right.

Use https:// in the value only when your provider runs a TLS-terminating proxy endpoint and tells you so. SparkProxy's gateway ports take plain HTTP for the client-to-proxy hop, with HTTPS targets tunneled through CONNECT, so every example here uses http://.

no_proxy: Keep Local Traffic Off the Proxy

Once a proxy is exported, everything goes through it unless you exclude it, including calls to localhost, your package mirror on the LAN and the cloud metadata service. A sensible starting value:

export no_proxy="localhost,127.0.0.1,::1,10.0.0.0/8,192.168.0.0/16,.internal.sparkproxy.io,169.254.169.254"
export NO_PROXY="$no_proxy"

How entries match differs by tool:

Patterncurl 8.5.0GNU Wget 1.21.4
`example.internal`That host and its subdomainsDomain suffix
`.example.internal`Subdomains (leading dot)Domain suffix
`10.0.0.0/8` (CIDR)Yes, since curl 7.86.0No
`*` aloneBypass everythingNot documented

The curl manual documents CIDR support ("added in 7.86.0") and adds a detail worth knowing: NO_PROXY "disables use of the proxy even when specified with the -x, --proxy option." Wget's manual describes no_proxy only as "a comma-separated list of domain extensions," with no mention of address ranges, so list internal IPs explicitly if Wget is in the mix. Spaces inside the list are a frequent typo; keep it comma-only.

Persist It: Shell rc, /etc/environment, /etc/profile.d

Exports vanish when the terminal closes. Where you make them permanent decides who sees them:

LocationWho reads itShell syntax?Good for
`~/.bashrc`Your interactive bash shellsYesOne user, terminal work
`/etc/profile.d/proxy.sh`Login shells of every userYesAll users, SSH logins
`/etc/environment`PAM: logins, sudo, cron on Ubuntu**No**, plain `KEY=VALUE`Machine-wide, non-shell processes
systemd `Environment=`One serviceUnit file syntaxDaemons and timers

~/.bashrc: Ubuntu's default file starts with a guard ("If not running interactively, don't do anything") that returns early. Exports appended at the bottom never reach a non-interactive bash, so a script started over ssh box 'cmd' or from cron won't see them. Put the exports in their own file and source it from both places:

# ~/.proxy.env  (chmod 600)
export http_proxy="http://spark_user:s3cr3t%402026@gateway.sparkproxy.io:11000"
export https_proxy="$http_proxy"
export no_proxy="localhost,127.0.0.1,::1"
export HTTP_PROXY="$http_proxy" HTTPS_PROXY="$https_proxy" NO_PROXY="$no_proxy"

# then, near the TOP of ~/.bashrc, above the interactive guard:
# [ -f ~/.proxy.env ] && . ~/.proxy.env

/etc/profile.d/proxy.sh: Ubuntu's /etc/profile sources every *.sh file in that directory, so a file there applies to all users' login shells. Same shell syntax as above, readable by everyone, so prefer IP whitelisting over embedded passwords here.

/etc/environment: this one is read by the pam_env module, not by a shell. The pam_env man page describes it as "simple KEY=VAL pairs on separate lines." We confirmed what that means in practice by appending these lines and opening a fresh sudo session:

# /etc/environment (test lines)
https_proxy="http://envtest.invalid:3128"
PROXY_HOST=gateway.sparkproxy.io
all_proxy="http://${PROXY_HOST}:11000"

The session received all_proxy=http://${PROXY_HOST}:11000, literally. No variable expansion happens, no export keyword is allowed, and the surrounding quotes are stripped. Write each full URL out on its own line. An already-open terminal also saw none of the new values, because PAM only applies the file when a session starts. Log out and back in to pick it up.

sudo, apt, cron and systemd Ignore Your Shell

The classic report: curl works, sudo apt update hangs. That's sudo doing its job. The sudoers manual says "By default, the env_reset flag is enabled. This causes commands to be executed with a new, minimal environment." With https_proxy exported in our test shell, sudo env showed no proxy variables at all, and sudo -E env showed them.

Ubuntu 24.04 ships the fix pre-written and commented out in /etc/sudoers:

#Defaults:%sudo env_keep += "http_proxy https_proxy ftp_proxy all_proxy no_proxy"

Uncomment it with sudo visudo to keep those five names for members of the sudo group. Note it lists lowercase only. There's a second path we found while testing: Ubuntu's /etc/pam.d/sudo loads pam_env.so readenv=1, so values in /etc/environment came through sudo even with env_reset on. If the proxy belongs to the whole machine, /etc/environment already covers sudo.

apt has its own setting, which is the cleaner choice because it doesn't depend on who runs apt. The apt-transport-http manual says http_proxy "is supported for system wide configuration" and that APT-specific proxies go in Acquire::http::Proxy:

sudo tee /etc/apt/apt.conf.d/95proxy >/dev/null <<'EOF'
Acquire::http::Proxy "http://spark_user:s3cr3t%402026@gateway.sparkproxy.io:11000/";
Acquire::https::Proxy "http://spark_user:s3cr3t%402026@gateway.sparkproxy.io:11000/";
EOF
sudo chmod 600 /etc/apt/apt.conf.d/95proxy

cron never reads ~/.bashrc. On Ubuntu, /etc/pam.d/cron loads pam_env.so, whose comment says it reads "/etc/environment and /etc/security/pam_env.conf." So machine-wide values reach cron jobs; per-user ones need . ~/.proxy.env at the top of the job's script.

systemd services start from the service manager, not a login, so none of the files above apply. Add the variables to the unit with a drop-in:

sudo systemctl edit my-scraper.service
# add:
# [Service]
# Environment="https_proxy=http://gateway.sparkproxy.io:11000"
# Environment="no_proxy=localhost,127.0.0.1"
sudo systemctl restart my-scraper.service
systemctl show my-scraper.service --property=Environment

EnvironmentFile=/etc/scraper/proxy.env works too, with plain KEY=VALUE lines and # comments per the systemd.exec manual (systemd 255 on Ubuntu 24.04). Containers are a separate layer with three places to configure; the Docker proxy guide walks through daemon, build and runtime.

Keep Proxy Credentials Out of History and ps

A password in https_proxy leaks in three places: ~/.bash_history, the environment of every child process (readable through /proc//environ by the same user and root), and anything that logs env output, such as CI debug steps.

Three habits help. First, keep the exports in a mode-600 file like ~/.proxy.env and source it, so the password never gets typed at a prompt. Second, if you must type one, Ubuntu's default HISTCONTROL=ignoreboth skips commands that start with a space, so prefix the line with one space. Third, and best for servers with a fixed address: drop the password entirely. SparkProxy supports IP whitelisting alongside user:pass, so an authorized server can use http://gateway.sparkproxy.io:11000 with nothing secret in it. How the two methods differ at the protocol level is covered in how proxy authentication works and IP whitelisting for proxies.

Random Rotation, Sticky Sessions and SOCKS5 From Bash

The port you put in the variable picks the behavior. On SparkProxy's gateway:

PortBehaviorUse it when
`11000`Random Rotation, new IP per requestIndependent fetches: price checks, SERP pages, API polling
`11002`Sticky Sessions, the same IP held for 5 minutesMulti-step flows: login then fetch, paginated carts
`13000`SOCKS5Tools that speak SOCKS, or non-HTTP traffic

A script can switch ports per job without touching the global setting:

#!/usr/bin/env bash
set -euo pipefail
. ~/.proxy.env                                   # defaults: rotating port 11000

sticky() { https_proxy="${https_proxy/:11000/:11002}" "$@"; }

for i in 1 2 3; do curl -s https://api.ipify.org; echo; done          # three IPs, usually different
for i in 1 2 3; do sticky curl -s https://api.ipify.org; echo; done   # same IP for the session

For SOCKS5, curl and git accept all_proxy=socks5h://user:pass@gateway.sparkproxy.io:13000. The h makes the proxy resolve hostnames, so DNS lookups don't leave from your own resolver. Wget has no SOCKS support, and Python requests needs an extra package; the SOCKS5 setup guide has the per-language details.

On cost: SparkProxy plans are concurrency packs, "Starting from $75/month" in USD on the live pricing page (checked 2026-10-30), with unlimited bandwidth included. Retries and verification loops in a cron job don't burn a traffic allowance, so the thing to size is how many parallel connections your scripts open. The 24-hour free trial needs no credit card, which is enough time to wire up the variables above and confirm cron and systemd pick them up.

Proxy Error Strings and What Fixes Them

Every string below was produced in our Ubuntu 24.04 test, copied verbatim. Match yours, then apply the fix.

Exact outputCauseFix
`curl: (35) OpenSSL/3.0.13: error:0A00010B:SSL routines::wrong version number``https://` scheme on a plain HTTP proxyChange the value to `http://`
`curl: (56) CONNECT tunnel failed, response 407`Wrong username or passwordCheck credentials and URL encoding
`curl: (5) Unsupported proxy syntax in '...': Port number was not a decimal number between 0 and 65535`Unencoded `@` or `:` in the passwordPercent-encode it (`%40`, `%3A`)
`curl: (7) Failed to connect to ... port ...: Couldn't connect to server`Wrong host or port, or a firewall blocking egressCheck the port and outbound firewall rules
`Proxy tunneling failed: Proxy Authentication RequiredUnable to establish SSL connection.` (wget)Wget's version of the 407Same as the curl 407 row
`Error in proxy URL ftp://labuser/p%40ss%3Aw0rd@127.0.0.1:3128: Must be HTTP.` (wget)No `http://` scheme in the value; Wget guesses wrongAdd `http://` (curl accepted the same value)
No error, real IP shownVariable ignored: wrong case, `sudo`, or service contextCheck the case table and the sudo section

The silent last row is the worst, because nothing tells you the proxy wasn't used. Run env | grep -i _proxy in the exact context that fails (sudo env, or systemctl show for a service) before anything else.

Be clear about what the proxy can and can't fix. Every error in that table is a client-side configuration problem; switching providers won't change any of them. A different exit IP helps only when the request reaches the target and the target refuses it: HTTP 403 or 429 from the site, CAPTCHAs, or geo-restricted content. Our proxy error codes reference separates proxy-side status codes from target-side ones. For targets that also fingerprint TLS or require JavaScript, an environment variable is the wrong tool; the SparkProxy Scraping API at https://scrape.sparkproxy.io/api/v1 handles rendering server-side.

Verify the Exit IP in One Line

After any change, compare the direct IP with the proxied one. If the two differ, the variables are working in that context:

echo "direct: $(env -u http_proxy -u https_proxy -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy curl -s https://api.ipify.org)  proxied: $(curl -s https://api.ipify.org)"

Run the same line under sudo bash -c '...', inside the cron job, or in an ExecStartPre= for a service to test each context separately. If "proxied" matches "direct", go back to the case table: something in that context isn't reading the variable you set.

Frequently asked questions

FAQ

Put plain KEY=VALUE lines in /etc/environment for every PAM session (logins, sudo and cron on Ubuntu), or a shell script in /etc/profile.d/ for login shells. /etc/environment doesn't expand variables, so write each full proxy URL out. Users must log out and back in to see the change.

Set both to the same value. curl ignores uppercase HTTP_PROXY, and in our test GNU Wget 1.21.4 ignored every uppercase spelling, while Python and many other tools accept either. Lowercase takes precedence in curl and Python when both exist.

The scheme describes the connection to the proxy, not to the website. A normal proxy receives a plain-HTTP CONNECT request and then tunnels your end-to-end TLS session. Using https:// makes curl attempt TLS to the proxy, which fails with "wrong version number" on a plain HTTP proxy.

sudo's default env_reset starts commands with a minimal environment. Use sudo -E for one command, uncomment Ubuntu's env_keep proxy line in /etc/sudoers with visudo, or put the values in /etc/environment, which Ubuntu's sudo PAM stack reads.

Percent-encode the character inside the URL: @ becomes %40, : becomes %3A, # becomes %23. curl decodes these before sending credentials. An unencoded @ produces curl's "Unsupported proxy syntax" error.

curl matches domain suffixes, accepts a lone * to bypass everything, and supports CIDR ranges like 10.0.0.0/8 since curl 7.86.0. GNU Wget documents only domain suffixes, so list internal IP addresses individually when Wget is involved.

Special Discount · 20% off

Get 20% off your first month

Premium datacentre proxies with unlimited bandwidth. Use the code at checkout.

Save up to 15% more on quarterly, half-yearly and yearly plans

Claim Discount

About the Author

The SparkProxy Technical Team builds and runs SparkProxy's datacenter proxy network and Scraping API. We write from hands-on testing: the case-sensitivity results and error strings in this guide come from our own Ubuntu 24.04 test runs on 2026-10-30, and every other claim is drawn from the curl, Wget, sudoers, pam_env, APT and systemd manuals for the versions named.

Keep reading

Related articles