How do I get add-apt-repository to work through a proxy?

Solution 1:

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>

Solution 2:

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 keyserver.ubuntu.com --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:[email protected]:3128/ --keyserver keyserver.ubuntu.com --recv-keys C2514567EEA14886

where,

USER_ID=user
PASSWORD=abc123
PROXY_URL=10.10.2.21
PORT=3128

If you don't have user authentication simply use,

sudo apt-key adv --keyserver-options http-proxy=http://10.10.2.21:3128/ --keyserver keyserver.ubuntu.com --recv-keys C2514567EEA14886