I need to run a command to initialize environment for an application. This needs to happen just once when snap package is installed.

DEB packages provide post-install script that serves this and many other purposes like setting up application specific user accounts and such.

So, what is DEB's post-install script equivalent in snap packages?

2 Answers 2


There is no post* script on purpose (to ensure that you have transactional updates).

Some hooks system though would be released very soon in snapd itself to enable you achieving this. It's not available yet at this date though, but you can use $SNAP_DATA file flag to make your daemon wait until the user file up the configuration (via another command from the same snap for instance).

  • 1
    An example, perhaps? I barely follow this idea with $SNAP_DATA.
    – ILIV
    Commented Jul 4, 2016 at 9:04

You can configure the environment for the application in a launcher script that does it just before starting the application. What @didrocks says is that you can create a hidden flag file in $SNAP_DATA folder to know if the application has been launched previously or not.

For instance, you can have a bash script in $SNAP/bin/myapp-launcher.sh that performs:

if [ ! -e "$SNAP_DATA/.flag_file ]; then
  <configure the app>
  touch $SNAP_DATA/.flag_file
exec "<command of your app>" "$@"

and in snapcraft.yaml configure that app to be started by calling its launcher, like

    command: bin/myapp-launcher.sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .