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.

  • Can you clarify what you mean by "ignored"? If the environment variable is indeed set but its value is not being used, then you have a Java configuration problem, and not an environment issue. I have never needed to set $JAVA_HOME but I always use the distribution's pre-packaged java install. – jw013 May 14 '12 at 15:13
  • @jw013 I mean that it does not appear when I run env within bash, and naturally IntelliJ doesn't keeps complaining when run from the Gnome3 menu entry. – protoboolean May 14 '12 at 15:18
  • Did you restart gnome since you added that? – Mat May 14 '12 at 17:03
  • 1
    Have you a ~/.bash_profile and/or ~/.bash_login? They are preferred over ~/.profile, if they exist – enzotib May 14 '12 at 20:27
  • 3
    If you put the definition in .bashrc, it will only be available in applications launched from a terminal. If you put it in ~/.profile, the definition is read when you log in on most, but not all systems. This can depend on your distribution, on your login manager, on your session manager and on your desktop environment. What login manager do you use (e.g. gdm, kdm, …)? What session type do you select? What window manager are you running? What version of Debian? Also, do you have a ~/.bash_profile or ~/.bash_login, and does it work if you put the definition there? – Gilles 'SO- stop being evil' May 14 '12 at 23:06

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.


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.

| improve this answer | |
  • Sorry, but I think this is not the recommended way for a Debian system, is it? BTW, any idea why .profile seems to be ignored by Gnome/X11? – protoboolean Jun 18 '12 at 11:07
  • Ubuntu is mostly based on Debian, there should be no problem using this method. And .profile is only used by Bourne style shells. It has nothing to do with X. – bahamat Jun 18 '12 at 20:07

For Environment variables to be visible inside X11 applications you start from GNOME menus, you may want to export this variable in /etc/X11/xinit/xinitrc. This file is sourced when an Xsession is started.

| improve this answer | |

Actually, I find easier to use the desktop files to set the JAVA_HOME for an executable. As example for IntelliJ, being my JAVA_HOME at /opt/java, and my idea installation at /opt/idea I would use a desktop file containing:

[Desktop Entry]    
Comment=IntelliJ Idea
Exec=env JAVA_HOME=/opt/java /opt/idea/bin/idea.sh

Then you can use that desktop file on any desktop environment.

Edit: Forgot to point you to save your *.desktop file at ~/.local/share/applications to be able to find and use it on Gnome desktop environment.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.