Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to follow the "Installing Cross Toolchain on Ubuntu 10.04 (Lucid) and 10.10 (Maverick) Hosts" instructions on (on my Ubuntu 10.04 VM). The first step is:

sudo add-apt-repository ppa:linaro-maintainers/toolchain

But when I run that I get:

Error reading <urlopen error [Errno 110] Connection timed out>

I'm guessing the problem is with my configuration for my employer's proxy server, particularly for HTTPS.

When I opened in Firefox, I got "The connection has timed out". I then went into Firefox Preferences -> Advanced -> Network -> Settings... and set HTTP Proxy to "gateway" and Port to 8080, and checked "Use this proxy server for all protocols". Then the page loaded. This supports my theory.

I've tried setting the http_proxy and https_proxy environment variables (both lower and upper case):

$ set | grep -i proxy

I also tried changing them to:

$ set | grep -i proxy

And I tried adding this second line to /etc/apt/apt.conf:

Acquire::http::proxy "http://gateway:8080/";
Acquire::https::proxy "https://gateway:8080/";

But I continue to get the same error.

How do I troubleshoot this?

Update: I followed the instructions in the accepted answer to "Problem adding repositories and connecting from terminal behind a proxy" and got further:

$ sudo add-apt-repository ppa:linaro-maintainers/toolchain
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver --recv 1DD749B890A6F66D050D985CF1FCBACA7BE1F97B
gpg: requesting key 7BE1F97B from hkp server
gpgkeys: HTTP fetch error 7: couldn't connect to host
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0

I wonder if the "HTTP fetch error" means I also need to add "Defaults env_keep = http_proxy" to /etc/sudoers...

Update #2: I added:

Defaults env_keep="http_proxy"
Defaults env_keep="https_proxy" in Comment 18 for bug 516032, but I still get the same "gpgkeys: HTTP fetch error 7: couldn't connect to host" error.

And this is curious:

$ sudo env | grep proxy

...because http_proxy isn't there.

Any advice is appreciated.

Update #3: Since the host of my VM is a laptop, I took it home and tried there (with no proxies):

$ sudo add-apt-repository ppa:linaro-maintainers/toolchain
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver --recv 1DD749B890A6F66D050D985CF1FCBACA7BE1F97B
gpg: requesting key 7BE1F97B from hkp server
gpg: key 7BE1F97B: public key "Launchpad Linaro Overlay PPA" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

It worked. So problem is related to proxy configuration. But I suppose I have a workaround.

share|improve this question
Just for reference… – Deepak Rajput Oct 14 '11 at 10:01
up vote 118 down vote accepted

In addition to configuring proxies, tell sudo to preserve the environment with the -E option:

export http_proxy=http://<proxy>:<port>
export https_proxy=http://<proxy>:<port>
sudo -E add-apt-repository ppa:linaro-maintainers/toolchain

with username and password:

export https_proxy=https://<username>:<password>@<proxy>:<port>
share|improve this answer
This worked for me! :) Thanks! – RadiantHex Mar 1 '12 at 15:56
Ya really worked – Shashwat Kumar Mar 16 '13 at 9:00
-E (after doing all of the other stuff above) got it working for me. – payloader May 24 '13 at 17:47
and yes, the https_proxy configuration was necessary... :P – monkut Jun 14 '13 at 5:41
How to add proxy permanently and avoid -E switch? I've the /etc/environment file configured properly with the lines added... Thanks – Enrique Aug 31 '15 at 20:54

Use the following code in a terminal to add gpg key behind proxy,

sudo apt-key adv --keyserver-options http-proxy=http://USER:PASSWORD@PROXY_URL:PORT/ --keyserver --recv-keys GPG_KEY

And replace uppercase letters accordingly. If you are using a proxy without any user authentication (i.e., user name and password) use http-proxy=http://PROXY_URL:PORT/ instead.

For example to have GPG_KEY=C2514567EEA14886 you can use,

sudo apt-key adv --keyserver-options http-proxy=http://user:abc123@ --keyserver --recv-keys C2514567EEA14886



If you don't have user authentication simply use,

sudo apt-key adv --keyserver-options http-proxy= --keyserver --recv-keys C2514567EEA14886
share|improve this answer
That's the definitive solution! THAANKS! – linello Feb 28 '14 at 10:54
This does not actually "fix" add-apt-repository command execution. Indeed it works around one of its tasks. At least one additional command is necessary: sudoedit /etc/apt/sources.list.d/XXXX.list + manual edition to add the deb URLs... – Chucky Dec 2 '14 at 11:24
This is the best answer. – Vik Jan 12 at 12:06
This also worked for me. Thank you for the detailed explanation. – Chuck Conway Feb 4 at 16:14

Finally! You need to set https_proxy via:

export https_proxy=....

only set http_proxy is not enough.

And I needed to execute the add-apt-repository command as root, NOT via sudo.


sudo su
add-apt-repository ppa:........
share|improve this answer

It seems that the proxy configuration is set up but somehow the server cannot be contacted...

I had a very similar issue which I resolved like this: The corporate proxy allows only port 80 and 443 for security reasons, so event when it is setup, since HKP protocol is using port 11371, it will not let you through.

So, short of SSH-ing out and getting the key from one of your servers outside, downloading it and installing it locally, you can specify the key server from on of the ones listed below and specify the port:


apt-key adv --keyserver hkp:// --recv-keys XXXXX

Boom, Voila!

share|improve this answer
Yup. This worked, for me, while installing Mono on Debian 7: sudo -E apt-key adv --keyserver hkp:// --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF – ken Apr 14 '15 at 14:41

This helped me:

sudo https_proxy='https://user:password@proxyhost:port/' \
http_proxy='http://user:password@proxyhost:port/' \
ftp_proxy='ftp://user:password@proxyhost:port/' \
no_proxy=localhost,, add-apt-repository ppa:webupd8team/java

I guess that there are some environment variables which are not needed in the command but they do not harm.

share|improve this answer

The reason your sudoers change did not work as expected is that instead of:

    Defaults env_keep="http_proxy"
    Defaults env_keep="https_proxy"

You should have written:

    Defaults env_keep+="http_proxy"
    Defaults env_keep+="https_proxy"

Also make sure the space between Defaults and env_keep is a tab each time.

share|improve this answer

system wide environment variables should really be added to:


(use sudo/gksu)

but the error reported to you seems to state no gpg data was found so i would see if the proxy is somehow munging the output of encrypted traffic just a thought

so i would first open a 2nd term & run a continuous netstat to see if the connection to the proxy is in fact being made then check the proxy settings (if you have access) then if that does not give answers/cause last resort would be to tcpdump & inspect in wireshark

but as this is your employers proxy i would imagine it is pretty locked down & you aint gonna be able to get this kinda access so i'd say:

Get Back to WORK!


or try a http tunnel ;)

share|improve this answer

In /etc/apt/apt.conf.d/01proxy add something like this

Acquire::http { Proxy ""; };

This will proxy all aptitude downloads, but I think this is the only way to do this on the backend. If your proxy supports it, you can also use a url like http://my.proxy:port/ which I know works for apt-cache-ng

I'm not sure if add-apt-repository itsself uses these settings, but if you cannot make that work, you can always add the repository to your /etc/apt/sources.list or /etc/apt/sources.list.d/mytoolchain

Since 11.10 there is also a cross-toolchailable in the main repo, just apt-get install gcc-arm-linux-gnueabihf. There are also cross-toolchains available from emdebian, and some instructions here:

share|improve this answer
user72421: how did you know that proxy should be prefixed with 01 and not with another number? – jgomo3 Sep 27 '13 at 23:22
Doesn't work with apt-get & keyserver – Vik Jan 12 at 12:07

Execute the below command in terminal

export http_proxy=
export ftp_proxy=http://username:password@proxyserver.netport/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.