I have created a snap and the software inside it reads certain configuration values from environment variables. I see that I can read environment variables this way and I am able to set environment variables at compile time by specifying them in
snapcraft.yaml however I haven’t been able to find any documentation on how to change environment variables after installing the snap.
What’s the best way to handle this scenario?
Did you manage to find an answer to your problem? I am having the same requirement. I need to set an environment variable in a snap application. It looks like I could go and maintain one of the files inside the snap under /snap, but that does not seem right and the next time the snap updates, I won’t have that change in the new snap version.
The standard way is to write a shell script to launch your application. This shell script can export the environment variables you require based on settings supplied to snapd via
snap set. The script accesses these settings by calling
Yes, I started using the dotenv library to store my env variables in a file and then from my application I load from
Thanks very much for the explanation. I will log an issue with the Rocket Chat snap maintainer and see whether they can incorporate this.
There seems to not be a
snapctl get command:
Also looking for a way to set environment variables for the snap app.
That doc page you found is for a different snap (i.e. Intel’s telemetry project): https://github.com/intelsdi-x/snap
You probably want to look at https://docs.snapcraft.io/supported-snap-hooks