we’ve developed a java application which has some configurations that has to be changed according to the
user needs. we’re using the properties file for the configuration and it is placed in the app’s root directory.
After the snap package, I cannot edit this file since it is read only. I want the properties file to be editable for my users.
How to make the configuration file editable inside snap?
Usually the thing to do is to have an install hook which will copy the configuration files from $SNAP and into $SNAP_DATA or $SNAP_USER_DATA, both of which are writable and then point your application to read their config files from there. Then a user can edit those configuration files and your application will pick up the changes.
You don’t have to declare the network plug for your install hook unless you need to access the network. If all you need the install hook to do is copy files, this is unnecessary and you can omit that snippet from your snapcraft.yaml.
Hooks are implemented with files of the same name living in snap/hooks/..., or being put there by a part in your snapcraft.yaml. So the simplest thing for you may be to just create the file snap/hooks/install and make that executable, and put a basic shell script like this in that file:
if [ ! -f $SNAP_USER_DATA/config.txt ]; then
cp $SNAP/config.txt $SNAP_USER_DATA/config.txt
You should just be able to create the hooks dir in the snap folder in your project’s root directory, i.e. if your project is located in your home folder under project1, then you would have snapcraft.yaml either at:
and run snapcraft from
In both of these cases, put the install hook here (with the filename verbatim install):
the install hook only runs during installation of the snap.
this means it runs as root and not as some user.
as such, the $SNAP_USER_DATA variable only points to /root/snap/<packagename>/current/ at that time.
if you want to copy to $SNAP_USER_DATA during first start of the app when a user runs it (so the variable actually points to that users dir), you rather want to run your app from a wrapper script with a line like:
@ogra The solution you proposed works fine. But should I have to hardcode the config file path ($SNAP_USER_DATA/config.properties) inside my code or is there any other method to mention the path of configuration file?