我希望在我的机器上有不同的Java版本.
我出于这个原因安装了jenv.但是,我无法为其设置所需的Java版本.实际上无法设置任何版本.
我安装了Java 8和11.我想将Java 8设置为全局
这是我试过的片段:
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)
我无法理解那里错过了什么.
如何用jenv设置Java 8?
解决方法:
我在终端执行:
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
之后它可以配置jenv,如手册页中所述.但是,它没有生效:
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
只有在打开新终端后我才能看到:
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)