How to Configure Proxy on Ubuntu & Debian Linux
Updated:
On Ubuntu and Debian Linux, proxy settings are scoped by execution context: shell sessions read /etc/environment or ~/.bashrc, the APT package manager reads /etc/apt/apt.conf.d/, systemd services read drop-in unit files, and GNOME Desktop uses gsettings. This guide provides exact configuration snippets for every Ubuntu subsystem using VinaProxy HTTP(S) proxies.
export http_proxy=http://user:pass@ip:port https_proxy=http://user:pass@ip:port- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
- 1 IP₫40,000
- 5+ IPs₫35,000
- 10+ IPs₫25,000
- 20+ IPs₫25,000
- 50+ IPs₫25,000
- 100+ IPs₫25,000
- 200+ IPs₫25,000
- 500+ IPs₫25,000
- 1000+ IPs₫22,000
- 2000+ IPs₫20,000
Ubuntu Proxy Configuration Scopes
sudo strips user environment variables by default, and systemd services do not read ~/.bashrc. Use this reference table to configure the right file on Ubuntu:
| Ubuntu Subsystem | Config File / Command | Applies To | Persistence |
|---|---|---|---|
| Interactive Shell | ~/.bashrc or /etc/profile.d/proxy.sh | curl, wget, python, git, node | Every login shell |
| System-Wide PAM Env | /etc/environment | All PAM user sessions | Across reboots |
| APT Package Manager | /etc/apt/apt.conf.d/80proxy | sudo apt update & apt install | Permanent for APT |
| systemd Services | /etc/systemd/system/<svc>.service.d/proxy.conf | Docker daemon, custom services | After daemon-reload |
Step-by-Step Setup on Ubuntu Server & Desktop
bash
# 1. /etc/profile.d/proxy.sh (Shell & CLI tools)
sudo tee /etc/profile.d/proxy.sh > /dev/null << 'EOF'
export http_proxy="http://USER:PASS@IP:PORT"
export https_proxy="http://USER:PASS@IP:PORT"
export HTTP_PROXY="http://USER:PASS@IP:PORT"
export HTTPS_PROXY="http://USER:PASS@IP:PORT"
export no_proxy="localhost,127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
export NO_PROXY="$no_proxy"
EOF
source /etc/profile.d/proxy.sh
# 2. /etc/apt/apt.conf.d/80proxy (APT package manager)
sudo tee /etc/apt/apt.conf.d/80proxy > /dev/null << 'EOF'
Acquire::http::Proxy "http://USER:PASS@IP:PORT/";
Acquire::https::Proxy "http://USER:PASS@IP:PORT/";
EOF
Preserving Proxy Variables Under sudo & Special Characters
- If you run commands via
sudo curl ...orsudo pip ..., passsudo -Eto preserve your exported proxy environment variables, or addDefaults env_keep += "http_proxy https_proxy HTTP_PROXY HTTPS_PROXY no_proxy NO_PROXY"viasudo visudo. - Restrict file permissions (
sudo chmod 600 /etc/apt/apt.conf.d/80proxy) on shared multi-user Linux servers so other local users cannot read your proxy credentials.
Step by step
- 1
Export Shell Environment Variables (/etc/profile.d/proxy.sh)
Create /etc/profile.d/proxy.sh defining both lowercase (http_proxy, https_proxy, no_proxy) and uppercase (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) variables so all GNU and Go/Rust CLI tools recognize them.
- 2
Configure APT Package Manager Proxy
Because sudo apt update ignores user shell variables, create /etc/apt/apt.conf.d/80proxy with Acquire::http::Proxy and Acquire::https::Proxy.
- 3
Test Outbound Connectivity with curl
Source your profile (
source /etc/profile.d/proxy.sh) and runcurl -s https://api.ipify.orgto verify your Ubuntu machine routes through VinaProxy.
Frequently asked questions
Why do I need both lowercase http_proxy and uppercase HTTP_PROXY on Linux?
Some Linux tools (like curl and wget) check lowercase http_proxy, while others works only with uppercase HTTP_PROXY (or both). Defining both guarantees consistent behavior across all runtimes.
Why does `sudo apt update` ignore my exported `http_proxy` variable?
sudo resets environment variables for security unless invoked with sudo -E. Configuring /etc/apt/apt.conf.d/80proxy ensures APT always uses the proxy cleanly.
How do I configure a proxy on Ubuntu Desktop GUI (GNOME)?
Open Settings → Network → Network Proxy → Manual, or use gsettings set org.gnome.system.proxy mode 'manual' along with org.gnome.system.proxy.http host and port.
Get low-latency HTTP(S) proxies for Ubuntu
Instant Dedicated IPv4 and Static ISP credentials across 7 countries.
View Proxy Pricing