Originally published on 2016-07-28; fully revised and updated.
If your network requires a proxy server, CLI tools may fail until proxy variables are configured. This guide helps DevOps engineers and administrators set http_proxy/https_proxy on Windows and Linux, make settings persistent, and fix common issues.
This revision is based on the original post: How to Set or Configure Proxy in Linux and Windows System.

When proxy settings are needed
- Your organization routes outbound traffic through a proxy or firewall.
- Commands such as package installs or API calls fail from terminal sessions.
- You need different proxy scopes: current shell, system-wide, or tool-specific (for example, apt).
Proxy setup workflow
Use this flow to choose the right level of configuration and troubleshoot quickly.
flowchart TD
A[Need outbound internet access] --> B{Operating system}
B -- Windows --> C[Set proxy in shell or system settings]
B -- Linux --> D[Export proxy variables]
C --> E[Test command line access]
D --> E
E --> F{Still failing}
F -- Yes --> G[Configure tool specific proxy such as apt]
G --> H[If using sudo pass proxy variables]
F -- No --> I[Done]
Windows vs Linux proxy methods at a glance
| Method | Platform | Scope | Best for | Notes |
|---|---|---|---|---|
| Shell environment variables | Windows / Linux | Current terminal session | Quick testing | Lost when terminal closes |
| System Environment Variables (GUI) | Windows | User or system-wide | Persistent app behavior | UI path varies by Windows version |
| Registry + WinHTTP import | Windows | WinINET and WinHTTP alignment | Centralized Windows proxy setup | Requires careful validation |
| /etc/environment | Linux | System-wide environment | Persistent host defaults | Credentials are stored in plaintext |
| APT proxy config | Linux (Debian/Ubuntu) | APT only | apt/apt-get behind proxy | Useful when environment variables are ignored |
Configure proxy on Windows
Temporary settings in Command Prompt
These values apply to the current Command Prompt session.
set http_proxy=http://your_proxy:your_port
set https_proxy=http://your_proxy:your_port
set no_proxy=localhost,127.0.0.1,.example.internal
set http_proxy=http://username:password@your_proxy:your_port
set https_proxy=http://username:password@your_proxy:your_portCode language: JavaScript (javascript)
Set environment variables via GUI
- Open Control Panel and select System.
- Open Advanced system settings, then click Environment Variables.
- Under System variables, click New.
- Add
http_proxyandhttps_proxywith your proxy URL.
Registry and WinHTTP commands
The original post includes registry-based setup and WinHTTP import:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /f
netsh winhttp import proxy source=ieCode language: JavaScript (javascript)
Enable, disable, or change proxy quickly
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /fCode language: JavaScript (javascript)
Legacy credential keys from the original post
The source also listed these keys; validate behavior in your Windows version before relying on them for authentication.
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyUser /t REG_SZ /d username
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyPass /t REG_SZ /d passwordCode language: JavaScript (javascript)
Configure proxy on Linux
Temporary settings for the current shell
export http_proxy=http://your_proxy:your_port
export https_proxy=http://your_proxy:your_port
export no_proxy=localhost,127.0.0.1,.example.internal
export http_proxy=http://username:password@your_proxy:your_port
export https_proxy=http://username:password@your_proxy:your_portCode language: JavaScript (javascript)
Persist settings in /etc/environment
The original FAQ points to /etc/environment for Ubuntu system-wide proxy values.
http_proxy="http://your_proxy:your_port"
https_proxy="http://your_proxy:your_port"
no_proxy="localhost,127.0.0.1,.example.internal"Code language: JavaScript (javascript)
Configure apt to use a proxy
If apt does not use your shell variables, add explicit proxy lines:
Acquire::http::Proxy "http://10.1.3.1:8080/";
Acquire::https::Proxy "http://10.1.3.1:8080/";Code language: PHP (php)
When sudo does not pass proxy variables
From the original FAQ: a common failure is that sudo does not pass the proxy environment variable by default.
sudo env http_proxy=http://10.1.3.1:8080 apt-get updateCode language: JavaScript (javascript)
FAQ and quick troubleshooting
- If your proxy password contains
@, try URL-encoding it as%40. - If manual
exportworks butapt-getwithsudofails, pass variables explicitly or adjust sudo policy. - Remember that some tools read environment variables, while others require tool-specific configuration.
echo $http_proxy
echo $https_proxy
echo $no_proxy
env | grep -i proxyCode language: PHP (php)
Common pitfalls and best practices
- Set both
http_proxyandhttps_proxyto avoid inconsistent behavior. - Avoid storing credentials in plaintext where possible; prefer secure secret handling mechanisms.
- Use URL encoding for special characters in usernames/passwords.
- Document a rollback path (for example, disabling proxy values) for incident response.
- Validate each target tool (curl, apt, build agents) because proxy handling differs by client.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals