5

My company uses an HTTP proxy and our various Ubuntu 12.04 servers therefore need to be configured properly, namely by setting \etc\apt\apt.conf.d\80proxy to:

Acquire::http::Proxy "http://proxy.mycompany.com:80";

Acquire::http::No-Cache true;

Now, since a few days, this method suddenly stopped working: I run into sum mismatch errors. I have tried all the usual tricks found on stackoverflow or on the web, among others:

sudo rm -fR /var/lib/apt/lists/*
sudo apt-get clean

But nothing seems to work. I even switched to a FTP server, without any luck. What's a radical solution to this problem? Is it likely that the proxy server has some kind of issue? What could it be?

Using Ubuntu 12.04

5 Answers 5

15

I've found that the following works for me, as far as using apt from the terminal alone is concerned:

  1. Leave /etc/apt/apt.conf empty, so that apt falls back on the $*_proxy environment variables.
  2. Make sure your environment variables are properly set: For example, you could add in .bashrc:

    http_proxy="http://username:password@proxyserver:port"
    # And so on for other proxy settings like https_proxy and ftp_proxy
    

    If your username or password contains any special characters, they may need to be URL encoded.

  3. Make sudo use your environment variables and not its own. This is done by editing the /etc/sudoers file. Be careful while doing this! Use only the sudo visudo command to edit the file; any errors may leave you unable to re-enter sudo mode! Add the following:

    Defaults env_keep+="http_proxy https_proxy ftp_proxy socks_proxy"
    

    This ensures that sudo retains these variables when executing sudo apt-get install ... etc.

I found this out from Ubuntu's apt-get howto.

Do let me know if it works :)

5
  • 1
    Did work for me! tks Oct 10, 2014 at 17:39
  • 4
    This is much better than the accepted answer. Jul 2, 2015 at 13:11
  • I think you can use set | grep -i proxy to check if the proxy is set - probably the reason I found the other method was because it somehow wasn't set.
    – Wilf
    Jul 27, 2015 at 22:19
  • 1
    Thank you so much! I have been working on this for days! Now it finally works!
    – Gumbo
    Nov 20, 2015 at 11:01
  • Hahaha, I did that wrong for years and always configured the proxy for apt additionally. With all due respect, what idiot came up with the idea that you need an empty configuration file for apt to read the http_proxy variable? Is there a use case where you have defined the proxy in /etc/environment and apt should not use it? OK, if I want to use apt-cacher-ng, but then I can do it explicitly in apt.conf?!
    – uav
    Jul 17, 2019 at 12:49
6

To use apt-get through a proxy, I do the following - you do need to be able to access the internet (e.g. through a browser like Firefox) though:

sudo apt-get --print-uris install PROGRAM

This prints the urls (and other info like md5sums) of the packages needed to carry out the installation, so you can download them. For example, using supertux:

wilf@comp:~$ sudo apt-get install --print-uris supertux
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  supertux-data
The following NEW packages will be installed
  supertux supertux-data
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 59.4 MB of archives.
After this operation, 80.0 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
'http://gb.archive.ubuntu.com/ubuntu/pool/universe/s/supertux/supertux-data_0.3.3-6_all.deb' supertux-data_0.3.3-6_all.deb 58590640 MD5Sum:68bd36f2c262f7caed1b5c947977202a
'http://gb.archive.ubuntu.com/ubuntu/pool/universe/s/supertux/supertux_0.3.3-6_i386.deb' supertux_0.3.3-6_i386.deb 804782 MD5Sum:a49c6c3c918bae2c968b3da6ac725b06

Then download the .deb files from the given links (preferably into a empty folder), through a browser that works through the proxy etc, and you can then install them using Software Centre; or using cd /FOLDER/WITH/DOWNLOADED-DEB-FILES and one of these commands in terminal

dpkg -i *.deb
gdebi *.deb 

This is a bit slow and annoying, but seems to work over HTTP proxies. You can also get the packages from http://packages.ubuntu.com/

2
  • 1
    Interesting approach, I didn't know about it.
    – Greg
    Feb 6, 2014 at 6:56
  • Instead of SOLVING the problem, always WORKAROUNDS... Welcome to Linux world!
    – Rodrigo
    Jul 25, 2016 at 15:47
2

To add to Wilf, I ran the following command to automate the download through Chrome. Firefox, I understand can be even simpler.

yes | sudo apt-get --print-uris install PROGRAM-NAME-HERE | grep http | awk '{print $1 }' | tr -d \' | while read -r line; do google-chrome "$line"; done

EDIT: so the whole answer will be in one post, once the downloads finish simply ran

cd /FOLDER/WITH/DOWNLOADED-DEB-FILES; dpkg -i *.deb
1

I don't know if you tried this already but what about:

export http_proxy=proxy.mycompany.com:80

You can check it afterwards with:

echo $http_proxy
1
  • Yes, unfortunately I tried pretty much all these little tricks found on the web :-(
    – Greg
    Feb 6, 2014 at 11:50
0

One trap here is that if after setting up your proxy as an unprivaleged user you run

sudo apt-get install REQUIRED_PACKAGE

where REQUIRED_PACKAGE is the software you want installed and you still see that it hangs when contacting tha machine beyond your proxy then it will likely work you pass -E to the sudo command as follows ...

sudo -E apt-get install REQUIRED_PACKAGE

This has the effect of running your command as root using your current environment (your proxy environment settings)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .