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
sudo nano /etc/environment
- Add Proxy Environment Variables
Include the following lines, replacinghttp://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.
- Save and Exit
Fornano
, pressCTRL+O
to save andCTRL+X
to exit.
- 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:
- Create a Proxy Configuration File
Create a new file in /etc/apt/apt.conf.d/:
sudo nano /etc/apt/apt.conf.d/95proxies
- 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/";
- 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!
becomesPa%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:
- Edit User’s Profile File
Open the.bash_profile
or.bashrc
file:
nano ~/.bash_profile
- 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"
- 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…