How to configure PATH and CLASSPATH for Java in Mac OS
How to configure PATH and CLASSPATH for Java in Mac OS
First, you need to find where the bin directory that contains all java binary files is located. To do that simply
cd /Library/Java/
Then do one “ls” to see what you have in this directory. Then continue cd to the inner directories to reach to the bin file. It might be a little different from me but my bin directory is in this path:
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/
In fact, Home is the path of the directory that contains the subdirectory named “bin” which contains all the java binary files needed for running java. This is the path that needs to be defined in PATH environment. keep this path.
Second, we need to check whether we have the.bash_profile or not. Simply cd to the home (I mean the user directory) — in any path if you just type cd and press enter, you can go to the home. When you are located in home, type this:
cat .bash_profile
if you see the error regarding a problem in finding the file then you need to create this file. For creating this file type this:
nano .bash_profile
you can see that the editor for writing into this file is open now. Then simply write this:
JAVA_HOME= /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/
export JAVA_HOME;
and ^O then enter then ^X to save this file.
Third, exit the terminal and reopen it and for testing whether you set the path environment or not write this comment in the terminal:
$JAVA_HOME/bin/java -version
If you see the correct version of java is showing up –Success!
Cite: http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/