8

I've created a .desktop file to launch our application. Our application requires, that a certain environment variable is configured correctly. Where can I configure this environment variable on a per-user base (the usual candidates I know, like ~/.bashrc and ~/.profile don't work).

Maybe there is a work-around, so I can configure it in the Exec= line of the .desktop file before launching the application?

1 Answer 1

17

In the desktop file itself, you can execute the program through env:

Exec=/usr/bin/env VAR=value /usr/bin/yourprogram

Alternatively, use a wrapper script (e.g. /usr/bin/yourprogram.env):

#!/bin/sh
VAR=value
export VAR
exec /usr/bin/yourprogram.real "$@"

However, both are poor solutions, since Unity will not be able to correctly track the program if it is started through a wrapper.

It would be much better to get ~/.profile working – make sure you're using the correct syntax and all that:

export VAR=value

or

VAR=value
export VAR

Also remember that ~/.profile is only read when you log in, so you must log out after changing it.

6
  • Thanks. Unfortunately, your suggestion to use env VAR=value /my/app does not work; the environment variable VAR is not set to value when /my/app launches (I've tried by editing the desktop file in ~/.gnome/apps). Creating a wrapper script is no option for me, because this should work for our application distributed to end-users and I don't know where the end-user would want the wrapper script to be located (creating the launcher must not require admin rights).
    – Mike L.
    Jul 4, 2012 at 14:03
  • (Huh? I didn't know ~/.gnome/apps was still in use; it's been called ~/.local/share/applications for the past few years.) @Mike, if it's your own application, why cannot it be fixed to automatically determine the proper environment variable? (Also, can I ask which variable specifically are you setting?) Jul 4, 2012 at 14:48
  • I'm trying to set a variable defining the location of the Java runtime environment for our application.
    – Mike L.
    Jul 4, 2012 at 19:31
  • 1
    perhaps use some of the standard locations standards.freedesktop.org/basedir-spec/basedir-spec-latest.html Jul 4, 2012 at 21:04
  • I've installed the .desktop file using xdg-desktop-menu install <my-desktop-file>. It looks like it copied it to two locations and I always was editing the wrong one...
    – Mike L.
    Jul 5, 2012 at 14:24

You must log in to answer this question.

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