In my project which need jdk 1.8, but there is default openjdk 17 in my mac. So I remove it from Library/Java/JavaVirtualMachines
. But when I run java -version it still shows my default jdk version is openjdk 17. And when I run /usr/libexec/java_home
it shows /Users/lidu/Library/Java/JavaVirtualMachines/openjdk-17/Contents/Home
. But I am sure that there isn't a directory called openjdk-17
in the path /Users/lidu/Library/Java/JavaVirtualMachines/
.
And when I run export JAVA_HOME=$(/usr/libexec/java_home -v "1.8.0_331")
it can be changed to jdk 1.8 but in the next time when I create a new terminal, it still shows the default jdk version is open jdk 17.
export will only persist in the terminal, if you run it manually.
Add the export JAVA_HOME command in .profile file at home directory, so that it will persist in every newly created terminal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.