Monday, October 29, 2018

macos - Installed Java 7 on Mac OS X but Terminal is still using version 6

In case if you have several Java versions on your machine and you want to choose it dynamically at runtime, i.e, in my case, I have two versions:



ls -la /Library/Java/JavaVirtualMachines
drwxr-xr-x 3 root wheel 96B Nov 16 2014 jdk1.7.0_71.jdk/
drwxr-xr-x 3 root wheel 96B Mar 1 2015 jdk1.8.0_31.jdk/


You can change them by modifying the /etc/profile content. Just add (or modify) the following two lines at the end of the file:




export JAVA_HOME=YOUR_JAVA_PATH/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH


In my case, it should be like the following if I want to use:



Java 7:



export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH


Java 8:



export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH


After saving the file, please run source /etc/profile and it should work. Here are results when I use the first and second option accordingly:




Java 7:



java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)


Java 8:




java -version 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)


The process is similar if your java folder is located in different locations.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...