How to set an environment variable when starting an application

To work around a bug in an application, I need to set an environment variable that it will see.

What’s the best way to do this?

I tried setting it in various /etc/profile, ~/.bash_profile etc. but none of these seem to affect the environment when an app is started from the gnome-shell launcher.

The best solution I can think of is to copy the .desktop file into ~/.local/share/applications and modify the commandline. I wonder if it’ll lead to a problem in the future when the package makes a change to the .desktop file and I don’t notice to update my copy of it. Is there a better way?

How is this application installed in your system? e.g. flatpak ?

It’s Fedora 32 and the app is installed using the system’s package manager.

There’s a neat trick with systemd (your case on Fedora), where you can create a file in your home directory and it will exported session wide.

Create, for example:
.config/environment.d/00-ardour-bug-8280.conf

And inside just put the var you want:
LV2_PATH=your-value

Your GNOME Session should pick that up automatically on login, and all apps and processes will see it available. It works fine for me for a few apps.

4 Likes

That looks like exactly what I need, thanks @diegoe

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.