setting JAVA_HOME on mac osx

How to set JAVA_HOME ON MAC OSX computer

Setting java_home as environment variable might be almost required especially when you use frameworks. Frameworks like axis2 web server and others. Also some code editors require that too.

What is environment variable

Those are variables that would allow you to execute command line actions from any directory, basically from everywhere.

The simplest example is using java -version. In this case, if you don’t have explicit environment variable on where to look for, it requires you to either be in the java folder or to fully list the whole path till bin folder.

Setting JAVA_HOME in mac osx

The first part is to make sure you have java installed in your machine.

java -version

If this is giving you an output with the version, then it means java is installed, otherwise, you should first install it.

The following task will be to find out where the binary files are located.

Click the apple icon on the left top corner of your mac and select system preferences..

system preference

system preference

And from there click Java and you will get the path information from there.

Once you got where the java is located, usually on /Library/Java/JavaVirtualMachines/jdk1.***/Contents/Home

Open the bash properties file


vi ~/.bash_profile

And add the java path here

export JAVA_HOME=export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

The above would be what it would look like fro jkd 1.8 on my El Capitan macbook pro.