Skip to main content
setproxyenvironmentvariableshow-to

How to Set Proxy Environment Variables (Linux, macOS, Windows)

Configuring proxy environment variables is the most effective way to force command-line tools, scripts, and development environments to route traffic throu…

P
ProxyPromo Editorial
July 12, 2026 · 8 min read
How to Set Proxy Environment Variables (Linux, macOS, Windows) — editorial cover illustration
In this article

Configuring proxy environment variables is the most effective way to force command-line tools, scripts, and development environments to route traffic through an intermediary server. Whether you are automating web scraping with Python or running apt-get updates on a remote server, understanding how to persist these settings across Linux, macOS, and Windows ensures seamless connectivity in restricted network environments.

The Architecture of Environment-Based Proxying

Environment variables are dynamic "named values" that can affect the way running processes behave on a computer. In the context of networking, variables like http_proxy and https_proxy serve as standardized flags that libraries (like cURL, Wget, or Python Requests) check before initiating a TCP connection. Unlike browser-based proxies that operate at the application layer with a GUI, environment variables work at the shell level.

When you set these variables, you are essentially telling every child process spawned by that terminal session to intercept outgoing requests and redirect them. This is critical for enterprise environments where a firewall blocks direct internet access, requiring a gateway for all HTTP and HTTPS traffic.

Diagram will load when scrolled into view
Flowchart: 6 nodes: Application/Terminal, Check Env Vars, Format: protocol://user:pass@host:port, Direct Connection, Proxy Server, Target Website6 nodes: Application/Terminal, Check Env Vars, Format: protocol://user:pass@host:port, Direct Connection, Proxy Server, Target Website; 7 connections
Text alternative
Flowchart
6 nodes: Application/Terminal, Check Env Vars, Format: protocol://user:pass@host:port, Direct Connection, Proxy Server, Target Website; 7 connections
graph TD
  A[Application/Terminal] --> B{Check Env Vars}
  B -->|Found| C[Format: protocol://user:pass@host:port]
  B -->|Not Found| D[Direct Connection]
  C --> E[Proxy Server]
  E --> F[Target Website]
  F --> E
  E --> A

It is important to note that while most modern tools respect these variables, some legacy applications or security-focused tools might ignore them to prevent accidental data leaks. For those specific cases, using a datacenter proxies from 1.75/IP setup provides the high-speed, stable endpoints needed to ensure the proxy remains responsive even under heavy load.

Setting Proxies in Linux and macOS (Bash/Zsh)

Linux and macOS share a common Unix-based foundation for environment variables. The syntax is identical, though the configuration files where you persist these settings vary. There are two primary ways to set these: temporarily (session-based) and permanently (profile-based).

Temporary Session Configuration

To set a proxy for the current terminal window only, use the export command. This is ideal for one-off tasks where you don't want to change your system-wide networking behavior.

# Setting HTTP and HTTPS proxies
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"

# Optional: Setting No Proxy for local traffic
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

# Verification
echo $http_proxy

Authentication and Special Characters

If your proxy requires a username and password, the format is http://user:password@host:port. However, if your password contains special characters like @, #, or :, you must URL-encode them. For example, a password of P@ssword! becomes P%40ssword!. Failing to encode these will cause the shell to truncate the variable, leading to authentication errors.

Permanent Global Configuration

To make these changes persist after a reboot, you must add the export commands to your shell profile.

  • For Bash (Ubuntu, CentOS, older macOS): Edit ~/.bashrc or ~/.bash_profile.
  • For Zsh (Modern macOS, Kali): Edit ~/.zshrc.

Add the lines to the bottom of the file, save, and run source ~/.zshrc to apply the changes immediately. For system-wide implementation across all users, Linux administrators often edit /etc/environment, though this file does not use the export keyword—it simply uses KEY=VALUE pairs.

High-Performance Proxy Comparison

When selecting a provider to use with these environment variables, latency and protocol support (SOCKS5 vs HTTP) are the most critical factors. High-load tasks like SEO auditing with Semrush or scraping via Bright Data require different configurations.

ProviderProtocol SupportAuth MethodReliabilityBest Implementation
Bright DataHTTP, HTTPS, SOCKS5User/Pass & IP99.9%Scripting & Scraping
OxylabsHTTP, HTTPS, SOCKS5User/Pass & IP99.8%Enterprise Data
SmartproxyHTTP, HTTPSUser/Pass99.7%Marketing Research
IPRoyalHTTP, SOCKS5User/Pass99.5%Affiliate Marketing
SOAXHTTP, HTTPSUser/Pass99.6%Mobile Data Needs

For users looking to save on these premium services, utilizing a 15% off all proxies code can significantly reduce the monthly overhead of maintaining multiple high-bandwidth residential pools.

Windows Environment Variable Configuration

Windows handles environment variables differently depending on whether you are using the traditional Command Prompt (CMD), PowerShell, or the System Settings GUI.

Using PowerShell (Modern Method)

PowerShell is the standard for modern Windows administration. To set a proxy variable for the current session:

$env:HTTP_PROXY = "http://proxy.server.com:port"
$env:HTTPS_PROXY = "http://proxy.server.com:port"

To make this change permanent for your user account without opening a GUI:

[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://proxy.server.com:port", "User")

Using the Command Prompt (CMD)

In the older CMD interface, the set and setx commands are used:

  • set HTTP_PROXY=http://proxy.server.com:port (Current session)
  • setx HTTP_PROXY "http://proxy.server.com:port" (Permanent)

System Settings GUI

  1. Press Win + R, type sysdm.cpl, and hit Enter.
  2. Go to the Advanced tab and click Environment Variables.
  3. Under "User variables", click New.
  4. Variable name: http_proxy | Value: http://yourproxy:port.
  5. Repeat for https_proxy.

Testing Your Proxy via Command Line

After setting your variables, it is crucial to verify that they are actually being used. The most reliable tool for this is curl. By requesting an IP echo service, you can see if the returned IP matches your proxy or your local ISP.

# Test HTTP
curl http://ifconfig.me/ip

# Test HTTPS (Crucial for verifying SSL/TLS interception)
curl https://api.ipify.org

# Test with verbose output to see the proxy connection phase
curl -v https://www.google.com

In the verbose output, look for a line that says * Uses proxy env variable http_proxy == '...'. If you see * Connected to proxy.example.com, your configuration is successful. If you are experiencing high latency during these tests, check your server's location or consider switching to a faster VPS-optimized proxy.

Performance Benchmark Statistics

Below are typical latency increases observed when routing via environment variables compared to a direct connection, based on an average of 100 requests to a global CDN.

  • Direct Connection: 15ms - 40ms (Baseline)
  • Datacenter Proxy (Env Var): 60ms - 120ms (+150% change)
  • Residential Proxy (Env Var): 150ms - 450ms (+800% change)
  • Mobile Proxy (Env Var): 300ms - 900ms (+1500% change)

For developers building high-speed applications, we recommend reading our guide on choosing the right proxy type to ensure your latency budgets are met.

Working with SOCKS5 and Special Tools

Standard http_proxy variables generally handle HTTP/HTTPS traffic. However, for protocols like SSH or FTP, or for bypassing UDP-based restrictions, SOCKS5 is preferred. To use SOCKS5 via environment variables, the syntax is:

export ALL_PROXY="socks5://user:pass@host:port"

Specific Configuration for Package Managers

Some tools like npm, git, and apt have their own internal configuration systems that might override or ignore system environment variables.

  • Git: git config --global http.proxy http://proxy.server.com:port
  • NPM: npm config set proxy http://proxy.server.com:port
  • APT: Create /etc/apt/apt.conf.d/proxy.conf and add Acquire::http::Proxy "http://proxy.server.com:port";

When using Git with high-volume repositories, ensure your provider, such as those found on 5-proxy.com, supports the large payload transfers required for binary objects.

Case Sensitivity: The Great Debate

One of the most common pitfalls in Linux environment variable configuration is case sensitivity. Historically, some programs looked for http_proxy (lowercase), while others looked for HTTP_PROXY (uppercase).

The Best Practice: Always set both.

export http_proxy="http://proxy.com:8080"
export HTTP_PROXY="http://proxy.com:8080"
export https_proxy="http://proxy.com:8080"
export HTTPS_PROXY="http://proxy.com:8080"

This ensures compatibility across a wide range of software, from older Perl scripts to modern Go binaries. If you are using Node.js for back-end development, double-setting these variables prevents the "Request Error: ECONNREFUSED" that often occurs when the runtime fails to detect the proxy.

Troubleshooting Common Issues

If your proxy is set but things aren't working, check the following:

  1. The "No Proxy" List: Ensure your no_proxy variable is set correctly. If you are trying to reach a local database (like MySQL or Redis) on the same machine, the application might be trying to reach it through the proxy, which will fail. Add localhost and 127.0.0.1 to no_proxy.
  2. SSL Certificate Errors: When using an HTTPS proxy that performs SSL inspection, curl and other tools may throw "SSL certificate problem: self-signed certificate". You will need to either ignore SSL (not recommended: curl -k) or add the proxy's CA certificate to your system's trust store.
  3. Firewall Restrictions: Ensure your local firewall or the network's hardware firewall allows outbound traffic on the proxy's port (common ports are 8080, 3128, and 1080).
  4. Credential Leaks: Never hardcode your proxy credentials in a public Git repository. Use a .env file or a secret management tool to inject these variables at runtime.

For those requiring reliable IPv6 support, checking specialized listings on proxytrust.site can provide endpoints that avoid the common "Network unreachable" errors found with IPv4-only proxy pools.

FAQ

Does setting http_proxy affect my web browser?

Generally, no. Modern browsers like Chrome and Firefox have their own internal proxy settings or use the system-level "LAN Settings" in Windows/macOS. Environment variables are specifically targeted at terminal-based applications and programming runtimes.

How do I unset a proxy variable?

In Linux or macOS, use the command unset http_proxy. In Windows PowerShell, use $env:HTTP_PROXY = "" or Remove-Item Env:\HTTP_PROXY. This will immediately stop the current session from routing traffic through the proxy.

Can I use a proxy environment variable with SSH?

Standard http_proxy variables do not affect SSH. To proxy SSH connections, you need to use the -o ProxyCommand flag in your SSH command or configure your ~/.ssh/config file to use a tool like nc (netcat) or corkscrew.

Why does my password fail when it has an '@' symbol?

The @ symbol is a reserved character in a URI, used to separate credentials from the hostname. If your password is user@123, it makes the string look like http://user@123@proxy.com. You must URL-encode the symbol as %40 for the system to parse it correctly.

Mastering the use of environment variables is a foundational skill for sysadmins and developers alike. By correctly configuring http_proxy, https_proxy, and no_proxy, you gain granular control over your network traffic, enabling faster development cycles and more robust automation. Always ensure you are using high-quality providers and keeping your credentials secure to maintain a performant and safe networking environment. For the best prices on the tools mentioned in this guide, check our latest proxy coupons.

P
Written by
ProxyPromo Editorial
Independent, engineer-written coverage of proxies, VPNs and SEO tooling. Every code we publish is manually tested.

Get the weekly ProxyPromo brief

Fresh deals, hand-tested codes and honest reviews — every Friday. No spam.

We'll send you a confirmation email. No spam — unsubscribe anytime.

Keep reading