Table of Contents
What you will read?
Setting a proxy on Ubuntu 25.04 via command line is useful for controlling internet access and routing traffic.
Step 1: Set a Temporary Proxy
This method sets the proxy only for the current terminal session; it resets after closing the terminal:
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
Check if the proxy variable is set:
echo $http_proxy
Step 2: Configure Proxy for a Single User
To keep the proxy active for your user across terminal sessions, add the settings to your shell profile:
nano ~/.bashrc
Add these lines to the end of .bashrc, then reload it:
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
source ~/.bashrc
Step 3: Set a System-wide Proxy
Set the proxy for all users and services by editing the system environment file:
sudo nano /etc/environment
Add the following lines and save the file:
http_proxy="http://proxy.example.com:8080"
https_proxy="http://proxy.example.com:8080"
Step 4: Configure Proxy for APT
APT requires a separate proxy configuration for package management:
sudo nano /etc/apt/apt.conf.d/95proxies
Add these lines to enable proxy for APT:
Acquire::http::Proxy "http://proxy.example.com:8080/";
Acquire::https::Proxy "http://proxy.example.com:8080/";
Step 5: Set Proxy for Snap
Snap requires its own proxy settings configured via snap commands:
sudo snap set system proxy.http="http://proxy.example.com:8080"
sudo snap set system proxy.https="http://proxy.example.com:8080"
Verify the Snap proxy configuration:
snap get system
