change java version in macOS BigSur

leonidas79 picture leonidas79 · Sep 25, 2020 · Viewed 7.6k times · Source

I can't change the java version in macOS BigSur. i have the following versions :

when I execute this command

/usr/libexec/java_home -V

i have the following versions :

Matching Java Virtual Machines (3):
    11.0.8 (x86_64) "Oracle Corporation" - "Java SE 11.0.8" /Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home
    1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home

i want to switch to java 1.8 as the default one , so I execute this command :

export JAVA_HOME=/usr/libexec/java_home -v 1.8.0_261

and then when I check java version :

java -version

I still got the old (higher one)

java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)

why it's not working?

Answer

Madhurish Gupta picture Madhurish Gupta · Sep 25, 2020

Please use below command :-

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_261`