-1

I am trying to downgrade the jdk for a project I'm running from 17.0.5 to 1.8, but have not been able to replicate any of the results I've found online. Specs and attempts below.

Specs:

MacOS Big Sur v11.6.8

Java v1.8.0_351

Javac v17.0.5

Gradle v7.6

Homebrew v3.6.16

Running /usr/libexec/java_home -V:

Matching Java Virtual Machines (4):
    17.0.5 (x86_64) "Oracle Corporation" - "Java SE 17.0.5" /Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home
    1.8.351.10 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_351 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home
    1.8.0_341 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home

First, I tried replicating the code from this answer regarding downgrading java:

https://stackoverflow.com/a/48422257/20834861

I quickly realized that the bash profile from sudo nano was already used to downgrade java to v1.8.

Then, I tried this solution: https://stackoverflow.com/a/23819062/20834861

But sudo mv jdk1.8.0_351.jdk ~/Desktop/ returns the following error: mv: rename jdk1.8.0_351.jdk to /Users/sahil/Desktop/jdk1.8.0_351.jdk: No such file or directory

So next, I tried the solution from this link:

https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/#java-home-and-macos-11-big-sur

When I tried the final line of code, echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home , I received the following error: zsh: permission denied: /Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home .

Finally, I tried a similar line of code but with source as the bash_file instead of zshenv. I got the same error.

I must be missing something really obvious but I could not find anything else on the internet. Any help is appreciated.

oguz ismail
  • 1
  • 16
  • 47
  • 69
  • Shouldn't it just be something like "export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk"? Then when you run java and javac it should use that java? What is `echo $JAVA_HOME /Library/...` supposed to accomplish? You can check the specific virtual machine by providing the full path to the bin. eg. `/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/bin/java` – matt Dec 24 '22 at 16:00
  • Honestly, you've kinda swamped this post with too much information. What you should do is follow this answer https://stackoverflow.com/a/46517346/2067492 and try to select a version of java you want. Start a shell, then `export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)` then check `java -version` and `javac -version`. Make sure `/usr/libexec/java_home -v 1.8` returns a valid JDK. – matt Dec 24 '22 at 16:07
  • @matt this worked great, thank you! If you submit it as an answer I'll approve it. Cheers – Sahil Sidhu Dec 24 '22 at 16:11

1 Answers1

0

With OSX you can select which jdk to use by using the JAVA_HOME environment variable. To set it.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home

That should work because it is in the list of jdk's you have available according to java_home. You can also use the java_home command to get the appropriate jdk.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Then when you run java or javac it should be from the version selected.

matt
  • 10,892
  • 3
  • 22
  • 34