Debian – How to expose JAVA_HOME to applications running under X and/or Gnome

debianenvironment-variablesgnome3intellijjava

I'm trying to run IntelliJ from Gnome3's Applications menu, but it complains the JAVA_HOME variable is not set.

I have the Java installation under my home folder.

I managed to export the variable in my ~/.bashrc:

export JAVA_HOME=~/jdk1.6.0_32

and I successfully ran IntelliJ from the command line.

I thought it's normal that configuration is ignored as Gnome should not assume we are using bash, isn't it?

I hoped that .profile to be the correct place to use, but it does not seem to have any effect.

Best Answer

According to Ubuntu's Wiki on Environment Variables either in ~/.pam_environment or in /etc/environment, depending on what you want it for all users, or just your user.

Session-wide environment variables

Environment variable settings that should affect just a particular user (rather then the system as a whole) should be set into:

~/.pam_environment - This file is specifically meant for setting a user's environment. It is not a script file, but rather consists of assignment expressions, one per line.

Note: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables.

And

System-wide environment variables

Environment variable settings that affect the system as a whole (rather then just a particular user) should not be placed in any of the many system-level scripts that get executed when the system or the desktop session are loaded, but into

/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.

Related Question