How can you change the default version of Java on a mac?
TOO EASY SOLUTION: What a headache - this was a quick easy solution that worked for me.
Mac OS Sierra Version 10.12.13
Use the shortcut keys: CMD+SHIFT+G - type in "/Library/"
Find the JAVA folder
Right Click Java Folder = Move to Trash (Password Required)
Install: Java SE Development Kit 8 jdk-8u131-macosx-x64.dmg | Download Javascript SDK
Use jenv is an easy way.
1.Install jenv
curl -s get.jenv.io | bash
2.Config jenv
cd ~/.jenv/candidates/
mkdir java
cd java
mkdir 1.7
mkdir 1.8
3.Symlink the jdk path
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin ~/.jenv/candidates/java/1.7
ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin ~/.jenv/candidates/java/1.8
4.You are all set
switch command:
jenv use java 1.8
set default:
jenv default java 1.7
tl;dr
Add the line:
export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home'
to the file
~/.bash_profile
(replace jdk1.8.0_144.jdk with your downloaded version)
then source ~/.bash_profile
Four easy steps using terminal for people who uses the default process.. :)
echo $JAVA_HOME
gives you current java home. For eg: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/
cd /Library/Java/JavaVirtualMachines/
will take you to the folder where u normally install jdks (It might be different for your machines)
ls
shows you available folders (normally it will have the version numbers, for eg: jdk1.8.0_191.jdk openjdk-11.0.2.jdk
)export JAVA_HOME='/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home'
will change the java home..