76

I know how to configure APT to use a web proxy. But what about snap?

6 Answers6

138

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

It works on Ubuntu LTS 14.04 and newer.

SebMa
  • 2,927
  • 5
  • 35
  • 47
Beta Kuang
  • 1,496
29

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.

Chipaca
  • 10,130
17

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
Simon Sudler
  • 4,111
9

Snap uses snapd daemon. You only need to define http_proxy and https_proxy in /etc/environment and restart the service: systemctl restart snapd.

user.dz
  • 49,176
mmartin
  • 91
2

Snap service is configured to use special environment file, so you can just add http_proxy variable to it if your current environment variables are not picked up by the snap.

Open file:

sudo vim /etc/sysconfig/snapd

Add:

http_proxy=http://127.0.0.1:3128
https_proxy=http://127.0.0.1:3128
Alex
  • 135
0

Be careful, because the snapd reads the /etc/environment file instead of get the ENV variable. This example below doesn't work:

export https_proxy=http://<your.ip.here>:3128

you have to use:

http://<your.ip.here>:3128