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/";


Acquire::http::Proxy "";
Acquire::https::Proxy "";

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/";
#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


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,


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

$ sudo apt install neofetch


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

five × five =