How to set JAVA_HOME on Mac OS X

Published on March 21, 2016 by Daniel Lanza

 mac  java

If you are planing to develop Java Apps on your Mac, you may have to set $JAVA_HOME environment variable.

Install the latest Java Virtual Machine

Go to How to install JDK on Mac OS X) to install a new Java Virtual Machine. Download the latest Java JDK package from Oracle.

Check Java Virtual Machines

List directories in the following root -> /Library/Java/JavaVirtualMachines

$ ls -l /Library/Java/JavaVirtualMachines
drwxr-xr-x  3 root  wheel  102 23 dic 20:36 jdk1.8.0_66.jdk
drwxr-xr-x  3 root  wheel  102 21 mar 14:20 jdk1.8.0_74.jdk

And the version for java will be the latest.

$ java -version
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

Set JAVA_HOME environment variable

Open your terminal, and create .bash_profile file if it does not exist.

vim .bash_profile

And write the following:

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

Refresh the environment variables by running the following command, and check the $JAVA_HOME value:

$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home
comments powered by Disqus

See also

How to resolve 404 error with Tomcat Server and Eclipse

If you start Tomcat from Eclipse and get a 404-Error code when you go to http://localhost:8080, there is a easy way to fix the issue. Just go to Properties for Tomcat (right click on Tomcat - Servers Tab) Switch location Tomcat Properties Switch location from [workspace metadata] to [/Servers/Tomcat v…] Restart Tomcat from Eclipse and go back to http://localhost:8080. You will see Tomcat configuration page. Tomcat configuration page

Read more

How to install JDK 8 on Mac OS X

If you are planing to develop Java Apps on your Mac, you have to install the JDK package. You only have to install the binary files provided by Oracle. Download JDK 8 from Oracle WebSite [jdk-8u65-macosx-x64.dmg for Mac] Double click on jdk-8u65-macosx-x64.dmg and follow the screen instructions JDK package will have been installed in /Library/Java/JavaVirtualMachines. In my computer, I have both 1.6 and 1.8 JDK package $ ls -l /Library/Java/JavaVirtualMachines drwxr-xr-x 3 root wheel 102 14 jul 23:52 1.

Read more

How to install Tomcat 7 on Mac OS X

Requirements: Java (at least 1.6). First, check your java version by opening the terminal: $ java -version java version "1.8.0_65" Java(TM) SE Runtime Environment (build 1.8.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode) Follow these steps: Download the binary Core Distribution from the original website (apache-tomcat-7.0.65.tar.gz): Apache Tomcat 7 Unzip the file downloaded Create a Tomcat folder in /Library. There we can leave several Tomcat versions to test

Read more