Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
OSX Yosemite, ZSH, and Java SE Runtime Environment 8, I had to:
$ sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands /System/Library/Frameworks/JavaVM.framework/Versions/Current/bin
and in ~/.zshrc change JAVA_HOME to
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/Current"
for macOS Mojave 10.14.1 and JAVA 11.0.1 I set the profile as
key in terminal this to confirm:
The above didn't work for me with Amazon's EC2 tools, because it expects
bin/java
etc. underneathJAVA_HOME
./System/Library/Frameworks/JavaVM.framework/Home
did work.If you are in need to have multiple versions of JDK under Mac OS X (Yosemite), it might be helpful to add some scripting for automated switching between them.
What you do is to edit your ~/.bash_profile and add the following:
What the script does is to first remove other JDK versions in the PATH so that they won’t interfere with our new JDK version. Then it makes some clever use of /usr/libexec/java_home which is a command that lists installed JDK versions. The -v argument tells java_home to return the path of the JDK with the supplied version, for example 1.7. We also update the PATH to point to the bin directory of the newly found JAVA_HOME directory. At the end we can simply execute the function using
which selects the latest installed JDK version of the 1.7 branch. To select a specific version you can simply execute
instead. Run /usr/libexec/java_home -V to get more details on how to choose versions.
P.S. Do not forget to source ~/.bash_profile after you save it.
On Mac OS X Lion, to set visualgc to run, I used:
Just set java_home of 1.8 jdk version in
netbeans.conf
file:uncomment line:
and set path to your 1.8 jdk, in my case:
This approach lays you to have several jdk versions on mac os