How to Configure Ubuntu CLI Proxy Settings?
Configuring a proxy server for command-line tools in Ubuntu is essential for downloading packages, updating software, and accessing external network resources within a restricted or corporate environment. Because CLI tools handle network requests differently than desktop environments, proxy settings must be applied directly to shell environment variables or specific package manager configuration files. This guide covers how to set up temporary and permanent proxy configurations for general terminal traffic, as well as specialized settings for the APT package manager.
Setting Up Temporary Environment Variables
If you only need to use a proxy for your current terminal session, you can export environment variables directly into the shell. These settings will disappear as soon as you close the terminal window.
Run the following commands in your terminal, replacing the placeholder IP and port with your actual proxy details:
export http_proxy="http://your.proxy.server:port"
export https_proxy="http://your.proxy.server:port"
export ftp_proxy="http://your.proxy.server:port"If your proxy server requires authentication, include your username and password in the URL format:
export http_proxy="http://username:password@your.proxy.server:port"Configuring Permanent Proxy Settings System-Wide
To ensure that every terminal session automatically uses the proxy server, you can add the environment variables to your system profile configurations.
- Open the
/etc/environmentfile using a text editor with administrative privileges:
sudo nano /etc/environment- Add the proxy variables to the bottom of the file:
http_proxy="http://your.proxy.server:port/"
https_proxy="http://your.proxy.server:port/"
ftp_proxy="http://your.proxy.server:port/"
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
- Save and close the file (in Nano, press
Ctrl+O,Enter, thenCtrl+X). - Log out and log back in, or run
source /etc/environmentto apply the changes immediately.
Configuring Dedicated Proxy Settings for APT
The Advanced Package Tool (APT) manages software installations in Ubuntu and sometimes requires its own dedicated configuration file to bypass general shell settings or enforce strict update routes.
- Create a new configuration file within the APT directory:
sudo nano /etc/apt/apt.conf.d/99proxy- Insert the following lines, ensuring each statement ends with a semicolon:
Acquire::http::Proxy "http://your.proxy.server:port/";
Acquire::https::Proxy "http://your.proxy.server:port/";
- Save and exit the file. APT will now route all
apt updateandapt installrequests through the designated proxy server.
Verifying the Configuration
To confirm that your command-line tools are communicating through the
proxy server properly, check the active environment variables and test
the connection using curl.
Verify the active variables by running:
env | grep -i proxyTest the actual network connectivity by requesting a public header:
curl -I https://www.ubuntu.comIf successful, the command will return a HTTP 200 OK status code, indicating that your Ubuntu command line is successfully routing traffic through the configured proxy.