0

I just installed JRE 8 from here but when I run java -version it produces the following output still:

My-MacBook-Pro-2:~ myusername$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

Why is this?

Apollo
  • 8,874
  • 32
  • 104
  • 192

2 Answers2

1
export JAVA_HOME=<path_to_jre_8>
export PATH="$JAVA_HOME/bin":$PATH

will tell the shell to use the java command from $JAVA_HOME/bin directory.

But this will only last for the current session.

You can put the same in ~/.bashrc for bash shell or the login config for the shell that you use.

Kishore
  • 819
  • 9
  • 20
0

Here is simple function in ~/.bash_profile file. Allows you to easy switch between JDK versions in MacOS.

function setjdk() {
  if [ $# -ne 0 ]; then
   removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
   if [ -n "${JAVA_HOME+x}" ]; then
    removeFromPath $JAVA_HOME
   fi
   export JAVA_HOME=`/usr/libexec/java_home -v $@`
   export PATH=$JAVA_HOME/bin:$PATH
  fi
 }
 function removeFromPath() {
  export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
 }
setjdk 1.8