Can't set different Java version in Mojave with jenv

Solution 1:

I executed in terminal:

echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile 
echo 'eval "$(jenv init -)"' >> ~/.bash_profile

And after it could configure jenv as it is described on the manual page. However, it didn't take effect:

sdos-MacBook-Pro:~ nazar$ jenv versions
  system
  1.8
* 1.8.0.192 (set by /Users/nazar/.jenv/version)
  11.0
  11.0.1
  openjdk64-11.0.1
  oracle64-1.8.0.192
sdos-MacBook-Pro:~ nazar$ java -version
openjdk version "11.0.1" 2018-10-16

Only after opening new terminal I could see:

sdos-MacBook-Pro:~ nazar$ java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)

Solution 2:

Not knowning about jenv, but macOS comes with a tool /usr/libexec/java_home to switch java version

Please refer to https://stackoverflow.com/questions/17885494/how-can-i-change-mac-oss-default-java-vm-returned-from-usr-libexec-java-home