5

I want to have different Java versions on my machine. I installed jenv for that reason. However, I can't set the desired Java version to it. Actually couldn't set any version.

I have Java 8 and 11 installed. I want to set Java 8 as a global.`

Here is snippet what I have tried:

sdos-MacBook-Pro:~ nazar$ ls -la /Library/Java/JavaVirtualMachines
total 0
drwxr-xr-x  4 root   wheel  128 Nov 28 16:58 .
drwxr-xr-x  5 root   wheel  160 Nov 19 19:41 ..
drwxr-xr-x  3 root   wheel   96 Nov 19 12:04 jdk1.8.0_192.jdk
drwxr-xr-x@ 3 nazar  staff   96 Oct  6 15:25 openjdk-11.0.1.jdk
sdos-MacBook-Pro:~ nazar$ jenv versions
* system (set by /Users/nazar/.jenv/version)
sdos-MacBook-Pro:~ nazar$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/
ln: /Users/nazar/.jenv/versions/oracle64-1.8.0.192: No such file or directory
sdos-MacBook-Pro:~ nazar$ ls -lg /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/
total 52224
-r--r--r--   1 wheel      3244 Oct  6 19:57 COPYRIGHT
-r--r--r--   1 wheel        40 Oct  6 19:57 LICENSE
-r--r--r--   1 wheel       159 Oct  6 19:57 README.html
-rw-r--r--   1 wheel    108062 Sep 12 12:20 THIRDPARTYLICENSEREADME-JAVAFX.txt
-r--r--r--   1 wheel    155003 Oct  6 19:57 THIRDPARTYLICENSEREADME.txt
drwxr-xr-x  46 wheel      1472 Oct  6 20:01 bin
drwxr-xr-x   3 wheel        96 Nov 19 12:04 bundle
drwxr-xr-x   9 wheel       288 Oct  6 19:57 include
-rw-r--r--   1 wheel   5207430 Sep 12 12:20 javafx-src.zip
drwxr-xr-x  10 wheel       320 Oct  6 19:58 jre
drwxr-xr-x  14 wheel       448 Oct  6 19:58 lib
drwxr-xr-x   5 wheel       160 Oct  6 19:57 man
-rw-r--r--   1 wheel       427 Oct  6 19:57 release
-rw-r--r--   1 wheel  21242800 Oct  6 19:57 src.zip
sdos-MacBook-Pro:~ nazar$ java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

I can't understand what is missed there.
How to set Java 8 with jenv?

4

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)
  • 1
    jenv init - did the trick for me. thank you – Eugene Feb 5 at 3:13
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .