Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I set JAVA_HOME environment variable on macOS X 10.6?

Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.

In macOS X 10.6, the following paths seem to be valid for this variable

/Library/Java/Home /System/Library/Frameworks/JavaVM.framework/Home /System/Library/Frameworks/JavaVM.framework/Versions/Current 

Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).

But which one should be used—or is it okay to use any of them?

like image 542
Robert Christie Avatar asked Aug 28 '09 19:08

Robert Christie


People also ask

What should I set JAVA_HOME to Mac?

In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home , just export $JAVA_HOME in file ~/. bash_profile or ~/. profile .

What should my JAVA_HOME be set to?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.


2 Answers

I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:

export JAVA_HOME=$(/usr/libexec/java_home) 

I haven't experienced any problems with that technique.

Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.5) 

For those of you who don't have java_home in your path add it like this.

sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home 

References:

like image 111
mipadi Avatar answered Sep 29 '22 10:09

mipadi


Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):

export JAVA_HOME=$(/usr/libexec/java_home)

Add also in ~/.profile:

export PATH=${JAVA_HOME}/bin:$PATH

P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc

like image 45
lucasarruda Avatar answered Sep 29 '22 08:09

lucasarruda