How to Configure apt-get behind proxy server for Ubuntu 14/15/16

After Installing Ubuntu 16.04 to make some monitoring tests, I was not able to get or update behind the http/https/ftp  proxy  . Here how i solved this.

i think this solution should work also  for  Debian 7/8 and LinuxMint 16/17

my machine :


Trying  to update

root@ubuntu:~# apt-get  update
Err:1 xenial-security InRelease
  Could not resolve ''
Err:2 xenial InRelease
  Could not resolve ''
Err:3 xenial-updates InRelease
  Could not resolve ''
Err:4 xenial-backports InRelease
  Could not resolve ''
Reading package lists... Done
W: Failed to fetch  Could not resolve ''
W: Failed to fetch  Could not resolve ''
W: Failed to fetch  Could not resolve ''
W: Failed to fetch  Could not resolve ''
W: Some index files failed to download. They have been ignored, or old ones used instead.

Follow the steps bellow to be able to execute apt-get behind a proxy:

Create new conf empty  file inside  /etc/apt/ and  do  the following

$ sudo vi /etc/apt/apt.conf

add this line  to the file if you are using  http proxy else  https of  ftp:

Acquire::http::Proxy "http://user:pass@proxy_host:port";


Acquire::http::Proxy "http://Domain\user:pass@proxy_host:port";

Now export the proxy line with:

export http_proxy=http://user:pass@proxy_host:port


export http_proxy=http://Domain\user:pass@proxy_host:port

To make this command permanent add it to ~/.bash.rc in your home directory:

vi ~/.bash.rc

Now Check and restart the updates:

root@ubuntu:~# apt-get  update
Hit:1 xenial-security InRelease
Get:2 xenial InRelease [95.8 kB]
Hit:3 xenial-updates InRelease
Hit:4 xenial-backports InRelease
Get:5 xenial/main amd64 Packages [1,442 kB]
Get:6 xenial/main i386 Packages [1,437 kB]
Get:7 xenial/main Translation-en [842 kB]
Get:8 xenial/universe amd64 Packages [7,353 kB]
Get:9 xenial/universe i386 Packages [7,343 kB]
53% [9 Packages 3,002 kB/7,343 kB 41%]

Upgrade Now:

root@ubuntu:~# apt-get  upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  ubuntu-minimal ubuntu-standard
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,944 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 xenial/main amd64 ubuntu-minimal amd64 1.349 [3,442 B]
Get:2 xenial/main amd64 ubuntu-standard amd64 1.349 [3,502 B]
Fetched 6,944 B in 0s (21.9 kB/s)
(Reading database ... 87004 files and directories currently installed.)
Preparing to unpack .../ubuntu-minimal_1.349_amd64.deb ...
Unpacking ubuntu-minimal (1.349) over (1.348) ...
Preparing to unpack .../ubuntu-standard_1.349_amd64.deb ...
Unpacking ubuntu-standard (1.349) over (1.348) ...
Setting up ubuntu-minimal (1.349) ...
Setting up ubuntu-standard (1.349) ...

To use wget behind proxy

sudo vi /etc/wgetrc

https_proxy  = http://username:password@proxy:port
http_proxy = http://username:password@proxy:port
http_proxy = http://Domain\username:password@proxy:port # (in case of LDAP)
ftp_proxy = http://username:password@proxy:port
Uncomment 'use_proxy = on'

Now  try to use  wget

root@ubuntu:~# wget
--2016-03-03 06:05:26--
Connecting to connected.
Proxy request sent, awaiting response... 200 OK
Length: 2674 (2.6K) [application/x-debian-package]
Saving to: ‘zabbix-release_2.4-1+trusty_all.deb’

Please remember this a real TEST behind a real proxy servers with Domain/user and password  needed.