Environment variables are widely used across Linux to provide convenient access to system and application properties.
Both Snapcraft and snapd consume, set, and pass-through specific environment variables to support building and running snaps.
See below for the various environment variables available to snap applications. For environment variables connected to Snapcraft, see Parts environment variables.
To get an overview of the environment of a specific snap, you can enter its shell and run the env command:
$ snap run --shell <snap>.<command>
$ env
XDG_VTNR=1
SSH_AGENT_PID=5543
XDG_SESSION_ID=2
SNAP_USER_COMMON=/home/<user>/snap/<snap>/common
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:
SNAP_COMMON=/var/snap/<snap>/common
[...]
Alongside the many system-specific variables, the snap environment will include the following :
SNAPDirectory where the snap is mounted. This is where all the files in your snap are visible in the filesystem.
All of the data in the snap is read-only and cannot be changed.
Typical value: /snap/hello-world/27
SNAP_ARCHCPU architecture of the running system.
Typical value amd64
Other values are: i386, armhf, arm64.
SNAP_COMMONDirectory for system data that is common across revisions of a snap.
This directory is owned and writable by root and is meant to be used by background applications (daemons, services). Unlike SNAP_DATA this directory does is not backed up and restored across snap refresh and revert operations.
Typical value: /var/snap/hello-world/common
SNAP_DATADirectory for system data of a snap.
This directory is owned and writable by root and is meant to be used by background applications (daemons, services). Unlike SNAP_COMMON this directory is backed up and restored across snap refresh and snap revert operations.
Typical value /var/snap/hello-world/27
SNAP_INSTANCE_NAMEThe name of snap instance, including instance key if one is set (snapd 2.36+).
For example snap hello-world with instance key foo has instance name equal to hello-world_foo.
Typical value: hello-world
SNAP_INSTANCE_KEYInstance key if one was set during installation or empty (snapd 2.36+).
For example instance hello-world_foo has an instance key foo.
Typical value: none
SNAP_LIBRARY_PATHDirectory with additional system libraries. This variable is used internally by snapcraft.
The value is always /var/lib/snapd/lib/gl: Please note the colon at the end of that value, the variable is a colon-separated list.
The referenced directory is typically empty unless Nvidia proprietary drivers are in use.
SNAP_NAMEThe name of the snap as specified in the snapcraft.yaml file.
Typical value: hello-world
SNAP_REAL_HOMEThe vanilla HOME environment variable before snapd-induced remapping, refer Any way to acquire the originally set HOME environment variable? - snapcraft - snapcraft.io for more info.
Available since snapd 2.46.
SNAP_REVISIONRevision of the snap, as allocated by the Snap Store on upload or as allocated by snapd for locally installed snaps.
The Snap Store assigns monotonic revisions to each upload of a given snap. Snapd uses Snap Store revisions if accompanying assertions are available or uses a locally generated number. Locally generated numbers are prefixed with x to distinguish them from Snap Store uploads.
Typical value: 27 or x1
SNAP_USER_COMMONDirectory for user data that is common across revisions of a snap.
Unlike SNAP_DATA, data present in this directory is not backed up or restored across snap refresh and snap revert operations. The directory is suitable for large data that the application can access even if it was made or modified by a future version of a snap.
Typical value /home/zyga/snap/hello-world/common
SNAP_USER_DATADirectory for user data.
This directory is backed up and restored across snap refresh and snap revert operations.
Typical value: /home/zyga/snap/hello-world/27
The final number there is $SNAP_REVISION.
SNAP_VERSIONThe version string as specified in the snapcraft.yaml
Typical value 6.3
HOMEThis environment variable is re-written by snapd so that each snap appears to have a dedicated home directory that is a subdirectory of the real home directory.
For classic confinement snaps, the value remains unchanged.
Typical value: /home/_user_name_/snap/_snap_name_/_snap_revision_ (e.g. /home/zyga/snap/hello-world/27)
PATHThis environment variable is re-written by snapd so that it is consistent with the view of the filesystem presented to snap applications.
The value is always:
For non-classic confinement snaps:
$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
For classic confinement snaps:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Last updated 3 months ago. Help improve this document in the forum.