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?

Mike L.
  • 5,617
  • 16
  • 50
  • 69

1 Answers1

16

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.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 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 04 '12 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?) – u1686_grawity Jul 04 '12 at 14:48
  • I'm trying to set a variable defining the location of the Java runtime environment for our application. – Mike L. Jul 04 '12 at 19:31
  • 1
    perhaps use some of the standard locations http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html – technosaurus Jul 04 '12 at 21:04
  • I've installed the `.desktop` file using `xdg-desktop-menu install `. It looks like it copied it to two locations and I always was editing the wrong one... – Mike L. Jul 05 '12 at 14:24
  • In what way will Unity be unable to track the program? – Sam Brightman Aug 02 '15 at 16:14