I know how to configure APT to use a web proxy. But what about snap?
-
could you please remove the "16.04" from the title? This topic is relevant for more or less every Ubuntu version. – Simon Sudler Jan 31 '23 at 08:39
-
There is a reported bug: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1579652 Please subscribe to check changes on it. – julian-alarcon May 26 '16 at 13:31
6 Answers
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>"

- 1,366
-
1I am using snap/snapd
2.34.2
on Ubuntu 16.04.5 and these options do not work. Had to go with https://askubuntu.com/a/1084862/75760 , changing the systemd settings – hanxue Aug 12 '19 at 08:38 -
The documentation specifies it works since snapd 2.28. Use
snap version
to check your current version. – DependencyHell Dec 17 '19 at 13:13 -
-
this answer really should be marked as ANSWER, works with Ubuntu1804 and
snap 2.37.4+18.04.1
, jsut a small reminder that if your password has special character, it should be encode (eg:!
=%21
) – Luke Mar 19 '20 at 07:35 -
-
Note that it is important to type that
http://
! (orhttps://
if applicable) – Cadoiz Dec 02 '21 at 12:21 -
error: cannot communicate with server: timeout exceeded while waiting for response – Line Dec 27 '21 at 17:04
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.

- 9,990
-
2Being more specific, the snapd.service file is located here: /lib/systemd/system/snapd.service – julian-alarcon May 26 '16 at 13:28
-
1@darkhole one shouldn't edit
/lib/systemd/system/snapd.service
, but usesystemctl edit snapd.service
. See my answer: http://askubuntu.com/questions/659267/how-do-i-override-or-configure-systemd-services – muru Jun 07 '16 at 13:57 -
1
-
2Remember, you will need to restart the snapd service before these changes take effect. – Seth Jan 11 '17 at 22:07
-
3The method you posted here also doesn't work with authentication. Snap should just use the normal $http_proxy and $https_proxy env vars like everyone else. Here is the ubuntu bug tracker link for this problem. – Teque5 Jan 31 '19 at 17:31
-
-
1@PauloPedroso Haha yes but mostly no. I manually downloaded the snap, extracted the contents since snap wouldn't let me install, mounted the squashfs that was inside, then ran once OK. After that I deleted the whole thing and swore off snaps forever; Flatpaks or docker images are a jillion times better. – Teque5 Feb 01 '19 at 01:51
-
@Teque5 I am out of Skype because of this. I don't believe I have the skills to do that in Skype. I have cursed snap last year because my linux install had problems and snapd wouldn't run. – Paulo Pedroso Feb 01 '19 at 11:45
-
1Teque, Paulo, snapd does use the default environment variables. I don't know what you're saying doesn't work. – Chipaca Mar 19 '19 at 14:49
-
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

- 3,931
- 3
- 21
- 34
Snap uses snapd
daemon. You only need to define http_proxy
and https_proxy
in /etc/environment
and restart the service: systemctl restart snapd
.
-
But remember if you add the proxy variables to the /etc/environment file, every other application will have this as their default environment as well – placid chat Aug 06 '21 at 07:26
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

- 137
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

- 11
- 1