如何降级 Java 版本,在其他操作系统应该也适用
题图用于怀旧
我也是因为在运行 neo4j 的时候遇到了 Java 版本的问题:
> ./neo4j console
...
WARNING! You are using an unsupported Java runtime.
* Please use Oracle(R) Java(TM) 11, OpenJDK(TM) 11 to run Neo4j.
...
复制代码
查看本地版本:
> java -version
java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
复制代码
一开始的想法是卸载掉当前的版本,重新安装。后来在 stackoverflow 上找到了
How to downgrade JDK on MacOShttps://stackoverflow.com/questions/46513639/how-to-downgrade-java-from-9-to-8-on-a-macos-eclipse-is-not-running-with-java-9
You don't need to down grade. You can run more than one version of Java on MacOS. You can set the version of your terminal with this command in MacOS.
# List Java versions installed
/usr/libexec/java_home -V
Matching Java Virtual Machines (4):
15.0.2 (x86_64) "Oracle Corporation" - "Java SE 15.0.2" /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
14.0.1 (x86_64) "Oracle Corporation" - "Java SE 14.0.1" /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
11.0.7 (x86_64) "Oracle Corporation" - "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
1.8.0_51 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
复制代码
发现自己的笔记本上有多个 JDK 的版本,然后在 .zshrc 里面添加
# Java 11
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
复制代码
再运行
就可以把 Java 的版本“downgrade” 到 Java 11
后来又遇到了
> ./neo4j console
...
... was successfully initialized, but failed to start. Please see the attached cause exception "Address already in use"
复制代码
使用 ps 命令查看进程,然后 kill 掉残余的 neo4j
> ps aux | grep neo4j
...
> bin kill -9 54839
复制代码
再次启动,终于看到了
> ./neo4j console --verbose
...
... INFO Started.
复制代码
我后来把 Java 的版本改回 15.0.2,启动 neo4j,虽然有警告,但是没有其他的影响。
评论