HomeLinuxHow to Set Up Proxy on Ubuntu/Debian via Command Line

How to Set Up Proxy on Ubuntu/Debian via Command Line

This guide shows how to set up proxy settings on the Ubuntu / Debian Command line without a GUI, by creating environment variables for system-wide settings and configuring applications like apt to use the proxy.

Configure System-Wide Proxy Settings in Linux

  1. Edit the /etc/environment File
    Open the file using a text editor such as Vim or nano:
sudo nano /etc/environment
  1. Add Proxy Environment Variables
    Include the following lines, replacing http://myproxy.server.com:8080/ with your proxy details:
http_proxy="http://myproxy.server.com:8080/"
https_proxy="http://myproxy.server.com:8080/"
ftp_proxy="http://myproxy.server.com:8080/"
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
HTTP_PROXY="http://myproxy.server.com:8080/"
HTTPS_PROXY="http://myproxy.server.com:8080/"
FTP_PROXY="http://myproxy.server.com:8080/"
NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"

Ensure both uppercase and lowercase variables are added as some applications may use one form over the other.

  1. Save and Exit
    For nano, press CTRL+O to save and CTRL+X to exit.
  1. Apply Changes
    Logout and log back in, or reboot the system:
sudo reboot

Configure Proxy for apt in Linux

The apt package manager does not automatically use system-wide proxy settings. Follow these steps to set a proxy for apt:

  1. Create a Proxy Configuration File
    Create a new file in /etc/apt/apt.conf.d/:
sudo nano /etc/apt/apt.conf.d/95proxies
  1. Add Proxy Settings
    Add the following lines, replacing http://myproxy.server.com:8080/ with your proxy details:
Acquire::http::proxy "http://myproxy.server.com:8080/"; Acquire::ftp::proxy "ftp://myproxy.server.com:8080/"; Acquire::https::proxy "https://myproxy.server.com:8080/";
  1. Save and Exit
    Save the file and exit the editor.

If your proxy requires authentication, include the username and password in the proxy URL like the below:

http://username:[email protected]:8080/

Note: Certain special characters in usernames or passwords must be URL-encoded. For example:

  • A password Pa$$word! becomes Pa%24%24word%21.
  • Use online tools or scripts to encode.

Temporary Proxy Settings in Linux

For a quick, temporary proxy setup, export variables directly in your terminal:

export http_proxy="http://myproxy.server.com:8080/"
export https_proxy="http://myproxy.server.com:8080/"
export no_proxy="localhost,127.0.0.1"

These settings last only for the session. To remove them, unset the variables:

unset http_proxy https_proxy no_proxy

Persistent Proxy Settings for Individual Users

To make proxy settings persistent for a specific user:

  1. Edit User’s Profile File
    Open the .bash_profile or .bashrc file:
nano ~/.bash_profile
  1. Add Proxy Variables
    Append the following lines:
export http_proxy="http://myproxy.server.com:8080/" export https_proxy="http://myproxy.server.com:8080/" export no_proxy="localhost,127.0.0.1,*.my.lan"
  1. Apply Changes
    Source the file to apply the changes:
source ~/.bash_profile

If changes don’t apply, restart the network manager (if available):

sudo service network-manager restart

Also, you can verify proxy settings by echoing the variables:

echo $http_proxy
echo $https_proxy

Following this guide, you can set up a proxy on the Ubuntu / Debian command line or minimal installations without a GUI. This allows your system and apps to use the specified proxy…

Scroll to Top