Ubuntu – How to get add-apt-repository to work through a proxy

add-apt-repositoryPROXY

I'm trying to follow the "Installing Cross Toolchain on Ubuntu 10.04 (Lucid) and 10.10 (Maverick) Hosts" instructions on wiki.linaro.org (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 https://launchpad.net/api/1.0/~linaro-maintainers/+archive/toolchain: <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 https://launchpad.net/api/1.0/~linaro-maintainers/+archive/toolchain 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
HTTPS_PROXY=https://gateway:8080
HTTP_PROXY=http://gateway:8080
http_proxy=http://gateway:8080
https_proxy=https://gateway:8080

I also tried changing them to:

$ set | grep -i proxy
HTTPS_PROXY=gateway:8080
HTTP_PROXY=gateway:8080
http_proxy=gateway:8080
https_proxy=gateway:8080

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 keyserver.ubuntu.com --recv 1DD749B890A6F66D050D985CF1FCBACA7BE1F97B
gpg: requesting key 7BE1F97B from hkp server keyserver.ubuntu.com
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"

…as 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
https_proxy=https://gateway:8080

…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 keyserver.ubuntu.com --recv 1DD749B890A6F66D050D985CF1FCBACA7BE1F97B
gpg: requesting key 7BE1F97B from hkp server keyserver.ubuntu.com
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.

Best Answer

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>