Canonical Snapcraft
Menu Close menu
  • Snap Store
  • About Snapcraft
  • Learn
    • Blog
    • Build
    • Docs
    • Tutorials
  • IoT
  • Forum
  • My account
    • My published snaps
    • My validation sets
    • My stores
    • Account details
    • Sign out
  • Sign in
Toggle side navigation
Toggle side navigation

Snap documentation

Use snaps

  • Snap tutorials
    • Get started
    • Install the daemon
      • AlmaLinux OS
      • Arch Linux
      • Debian
      • Elementary OS
      • Fedora
      • Linux Mint
      • Manjaro Linux
      • Raspberry Pi OS
      • openSUSE
      • Pop!_OS
      • Rocky Linux
      • Ubuntu
  • Snap how-to guides
    • Work with snaps
      • Manage updates
      • Connect interfaces
      • Configure snaps
      • Apps and aliases
    • Manage snaps
      • Create data snapshots
      • Use resource quotas
      • Disk space awareness
      • Set system options
      • Control services
      • Using components
      • Configure snaps with confdb
      • Manage validation sets
      • Snap deltas
      • Use the REST API
      • Use snapctl
    • Fix common issues
      • Test snapd fixes
      • Debug snaps
  • Snap reference
    • Operations
      • Glossary
      • System options
      • System architecture
      • Interfaces
        • Hardware interfaces
        • Media interfaces
        • Network interfaces
        • Security interfaces
        • System interfaces
        • Super-privileged interfaces
    • Administration
      • Network requirements
      • Distribution support
    • Development
      • Supported snap hooks
      • Environment variables
      • REST API
        • snapd REST API
        • Error responses
      • YAML schemas
        • The snap format
        • The gadget snap
        • The kernel snap
    • Release notes
  • Snap explanation
    • How snaps work
      • Refresh awareness
      • Channels and tracks
      • Revisions
      • Transactional updates
      • Validation sets
      • Confdb configuration mechanism
      • Snap components
      • Snap performance
    • Interfaces
      • All about interfaces
      • Interface auto-connection
      • Interface hooks
    • Security
      • Security policies
      • Snap confinement
      • Classic confinement
      • Assertions
      • Snapd release process

Build snaps

Contribute to our docs

Environment variables

On this page

  • Snap specific environment variables
    • List environment variables
  • Generic variables

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.

Snap specific environment variables

List environment variables

Each snap runs in a custom environment specifically made for it. To get an overview of the variables in it, you can open a shell as the snap 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, this environment will include the following:

SNAP SNAP_ARCH
SNAP_USER_DATA SNAP_UID
SNAP_USER_COMMON SNAP_EUID
SNAP_DATA SNAP_LAUNCHER_ARCH_TRIPLET
SNAP_COMMON SNAP_LIBRARY_PATH
SNAP_SAVE_DATA SNAP_VERSION
SNAP_INSTANCE_NAME SNAP_REAL_HOME
SNAP_INSTANCE_KEY HOME
SNAP_NAME PATH
SNAP_REVISION

SNAP

Directory 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_USER_DATA

Directory 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_USER_COMMON

Directory for user data that is common across revisions of a snap.

Unlike SNAP_USER_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_DATA

Directory 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_COMMON

Directory 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 is not backed up and restored across snap refresh and revert operations.

Typical value: /var/snap/hello-world/common

SNAP_SAVE_DATA

This variable is only exposed on Ubuntu Core systems.

It points to a snap-specific location on the ubuntu-save partition where the snap is allowed to store persistent files (like certificates or configuration files) that will survive a factory reset of the Ubuntu Core device.

See ubuntu-save in the Ubuntu Core documentation for more details on storage layout with this specific partition.

Requires snapd 2.57+.

SNAP_INSTANCE_NAME

The name of snap instance, including instance key if one is set.

For example snap hello-world with instance key foo has instance name equal to hello-world_foo.

Typical value: hello-world

Requires snapd 2.36+

SNAP_INSTANCE_KEY

Instance key if one was set during installation or empty.

For example instance hello-world_foo has an instance key foo.

Typical value: none

Requires snapd 2.36+

SNAP_NAME

The name of the snap as specified in the snapcraft.yaml file.

Typical value: hello-world

SNAP_REVISION

Revision 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_ARCH

CPU architecture of the running system.

Typical value amd64

Other values are: i386, armhf, arm64.

SNAP_UID

This variable contains the user ID (uid) of the user running this snap instance. See also SNAP_EUID.

For this variable to be exposed by a snap, the snap developer will need to include the following assumes value:

assumes: [snap-uid-envvars]

Requires snapd 2.59+.

SNAP_EUID

This variable contains the effective user ID (euid) of the user running the snap instance. See also SNAP_UID.

For this variable to be exposed by a snap, the snap developer will need to include the following assumes value:

assumes: [snap-uid-envvars]

Requires snapd 2.59+.

SNAP_LAUNCHER_ARCH_TRIPLET

Only available in snaps built with a desktop extension.

The host architecture triplet on which the snap is running. For amd64 it’s x86_64-linux-gnu. The runtime counterpart of CRAFT_ARCH_TRIPLET_BUILD_FOR.

SNAP_LIBRARY_PATH

Directory 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_VERSION

The version string as specified in the snapcraft.yaml

Typical value 6.3

SNAP_REAL_HOME

The vanilla HOME environment variable before snapd-induced remapping, refer to Any way to acquire the originally set HOME environment variable? - snapcraft - snapcraft.io for more info.

Requires snapd 2.46+.

Generic variables

HOME

For non-classic snaps, this environment variable is re-written to SNAP_USER_DATA 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)

PATH

This 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 6 months ago.

Help improve this document in the forum.

Back to top

© 2025 Canonical Ltd.

Ubuntu and Canonical are registered trademarks of Canonical Ltd.
Powered by Charmed Kubernetes

Join the forum, contribute to or report problems with, snapd, Snapcraft, or this site.

  • Terms of Service
  • Data privacy
  • Manage your tracker settings
  • Service status
  • Other functions
  • Share on Twitter
  • Share on Facebook
  • Share on YouTube