How to configure proxy for apt command on Ubuntu and Debian

In this post, we will learn how to configure proxy for apt command on Ubuntu and Debian system.

In most of the production environments, Ubuntu and Debian servers do not have direct internet connectivity. To install updates, one must configure proxy for apt command so that all the apt command requests go via proxy server.

APT proxy settings can also be enabled during the OS installation however if proxy settings are skipped during OS installation, then use the following steps to configure.

1 ) Create Proxy file under /etc/apt/apt.conf.d

Create a file name “proxy.conf” with following content

$ sudo vi /etc/apt/apt.conf.d/proxy.conf

Proxy without username and password

Acquire::http::Proxy "http://<proxy-server-ip>:port/";
Acquire::https::Proxy "http://<proxy-server-ip>:port/";

Proxy with Username and Password

Acquire::http::Proxy "http://username:password@<proxy-server-ip>:port/";
Acquire::https::Proxy "http://username:password@<proxy-server-ip>:port/";

Example:

Acquire::http::Proxy "http://10.217.32.229:8181/";
Acquire::https::Proxy "http://10.217.32.229:8181/";

Save and close the file.

Note: Please make sure there is network connectivity between Ubuntu / Debian system and proxy server. Try to make connection on proxy server on their port using telnet or curl command.

2)  Alternate way to enter proxy details in proxy.conf file

Use following alternate method to specify the proxy settings in /etc/apt/apt.conf.d/proxy.conf file.

$ sudo vi /etc/apt/apt.conf.d/proxy.conf
#Proxy without Username and password
Acquire {
  http::Proxy "http://<proxy-server-ip>:port/";
  https::Proxy "http://<proxy-server-ip>:port/";
}
#OR
#Proxy with username and password
Acquire {
  http::Proxy "http://username:password@<proxy-server-ip>:port/";
  https::Proxy "http://username:password@<proxy-server-ip>:port/";
}

Save and exit the file

Apt-Proxy-conf-Ubuntu-Debian

3) Test Proxy settings of apt command

Run the following apt command to test apt proxy,

$ sudo apt update

Output should be something like below,

Sudo-Apt-Command-After-Proxy-Settings

Great, above output confirms that we can reach to ubuntu repository, let’s try to install a neofetch package,

$ sudo apt install neofetch

Apt-install-package-example-after-proxy-settings

That’s all from this post. I hope you have found it informative. Please do post your queries and feedback in below comments section.

Also Read: Top 4 Screenshot Tools For Ubuntu / Debian Desktop

Leave a Comment

5 × 3 =