I know how to configure APT to use a web proxy. But what about snap?
-
There is a reported bug: bugs.launchpad.net/ubuntu/+source/snapd/+bug/1579652 Please subscribe to check changes on it.– julian-alarconMay 26, 2016 at 13:31
-
could you please remove the "16.04" from the title? This topic is relevant for more or less every Ubuntu version.– Simon SudlerJan 31 at 8:39
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>"
-
1I am using snap/snapd
2.34.2
on Ubuntu 16.04.5 and these options do not work. Had to go with askubuntu.com/a/1084862/75760 , changing the systemd settings– hanxueAug 12, 2019 at 8:38 -
The documentation specifies it works since snapd 2.28. Use
snap version
to check your current version. Dec 17, 2019 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
)– LukeMar 19, 2020 at 7:35 -
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.
-
2Being more specific, the snapd.service file is located here: /lib/systemd/system/snapd.service May 26, 2016 at 13:28
-
1@darkhole one shouldn't edit
/lib/systemd/system/snapd.service
, but usesystemctl edit snapd.service
. See my answer: askubuntu.com/questions/659267/…– muruJun 7, 2016 at 13:57 -
1
-
2Remember, you will need to restart the snapd service before these changes take effect.– SethJan 11, 2017 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.– Teque5Jan 31, 2019 at 17:31
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
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 Aug 6, 2021 at 7: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
-
1
-
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