How to install snap packages behind web proxy on Ubuntu 16.04
I know how to configure APT to use a web proxy. But what about snap?
A system option was added in snap 2.28 to specify the proxy server.
$ sudo snap set system proxy.http="http://<proxy_addr>:<proxy_port>"
$ sudo snap set system proxy.https="http://<proxy_addr>:<proxy_port>"
Documentation
snapd
reads /etc/environment
, so setting the usual proxy environment variables there works. On Ubuntu, that's done automatically for you by Settings → Network → Network proxy, so as long as you restart snapd
after changing that file you should be set.
There is another way to add environment variables to systemd services:
Create a folder for the snap daemon and create configuration files for the environment variables:
$ sudo mkdir -p /etc/systemd/system/snapd.service.d/
$ echo -e '[Service]\nEnvironment="http_proxy=http://1.2.3.4:3128/"' \
| sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
$ echo -e '[Service]\nEnvironment="https_proxy=http://1.2.3.4:3128/"' \
| sudo tee /etc/systemd/system/snapd.service.d/https-proxy.conf
$ sudo systemctl daemon-reload
$ sudo systemctl restart snapd
After that you can check if the environment variables are set for snapd
:
$ systemctl show snapd | grep proxy
Environment=http_proxy=http://1.2.3.4:3128/ https_proxy=http://1.2.3.4:3128/
DropInPaths=/etc/systemd/system/snapd.service.d/http-proxy.conf /etc/systemd/system/snapd.service.d/https-proxy.conf