In 2024, even if you can use just brew..
Copybrew install openjdk@17
Java will be installed here:
Copy/opt/homebrew/opt/openjdk@17/bin/java
for Apple Intel path is /usr/local/... rather than /opt/homebrew/...
For the system Java wrappers to find this JDK, symlink it with:
Copysudo ln -sfn /opt/homebrew/opt/openjdk\@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
resp. for Intel
Copysudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Now, running /usr/libexec/java_home -V should show the path to JAVA 17, something like:
Copy17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
(This is what you are missing btw, if javac or javac --version does not give you a command-not-found but an The operation couldn’t be completed. Unable to locate a Java Runtime.)
In case you see the wrong version, check if the path to JAVA_HOME is set correctly. If not, you could set it by:
Copyexport JAVA_HOME=\$(/usr/libexec/java_home)
...give a try to sdkman, it's far better than brew
Copycurl -s "https://get.sdkman.io" | bash
then open a new shell and try list to see what you could install ;-)
Copysdk list java
At time of writing you could use:
Copysdk install java 17.0.4.1-tem
Java will be installed here:
Copy/Users/YOUR_USERNAME_HERE/.sdkman/candidates/java/17.0.4.1-tem
Answer from freedev on Stack OverflowIn 2024, even if you can use just brew..
Copybrew install openjdk@17
Java will be installed here:
Copy/opt/homebrew/opt/openjdk@17/bin/java
for Apple Intel path is /usr/local/... rather than /opt/homebrew/...
For the system Java wrappers to find this JDK, symlink it with:
Copysudo ln -sfn /opt/homebrew/opt/openjdk\@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
resp. for Intel
Copysudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Now, running /usr/libexec/java_home -V should show the path to JAVA 17, something like:
Copy17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /opt/homebrew/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
(This is what you are missing btw, if javac or javac --version does not give you a command-not-found but an The operation couldn’t be completed. Unable to locate a Java Runtime.)
In case you see the wrong version, check if the path to JAVA_HOME is set correctly. If not, you could set it by:
Copyexport JAVA_HOME=\$(/usr/libexec/java_home)
...give a try to sdkman, it's far better than brew
Copycurl -s "https://get.sdkman.io" | bash
then open a new shell and try list to see what you could install ;-)
Copysdk list java
At time of writing you could use:
Copysdk install java 17.0.4.1-tem
Java will be installed here:
Copy/Users/YOUR_USERNAME_HERE/.sdkman/candidates/java/17.0.4.1-tem
Java doesn't mind if you install multiple versions. This is often required; java is not backwards compatible (it tries to change little, but e.g. the java8 to java9 transition broke a ton of stuff, much of it needless and much of it not reasonably expectable or fixable by libraries and apps, so a bunch of java apps and libraries only run on java8 - just an example).
So, yes, you have installed JDK17. Also, yes, if you just run java without specifying which one you want, you so happen to get java13 here.
To see all installed javas, you can run:
Copy/usr/libexec/java_home -V
to 'override', you can use something like (depends on which shell you're using on your mac):
Copyexport JAVA_HOME=`/usr/libexec/java_home -v 17`
(the backticks mean: Run this then take the output of it and treat that as the 'value' of the expression. here, assign it to the JAVA_HOME env var. -v 17 requests a path to java 17. The -V option lists all and is meant for your eyeballs, not for scripts. The -v option is mostly for scripting, and that's how we're using it here).
JAVA_HOME decides which java is used by some things, but the java you get when you just type java is /usr/bin/java, and that executable is actually just a wrapper that picks a java to run from amongst all installed versions. It uses JAVA_HOME to decide which java to actually run. There are wrappers for all the common commands (javac, too). You can always run e.g. which javac to see what that actually runs; you probably see /usr/bin/javac. Everything in /usr/bin is one of these wrapper thingies that looks at JAVA_HOME and then runs the binary it finds there.
how do you install arm jdks with sdkman?
java - is it possible install jdk from local using sdkman - Unix & Linux Stack Exchange
Installs 64 bit java on 32 bit VM
sdkman! How to manage pre-existing JDK? - Stack Overflow
Videos
when i install jdks with sdkman it installs x86_64. when i run `sdk list java` i'm not seeing any arm versions either. is there a setting or flag i need to add?
If you want to use your own directory you can run this command
sdk install java 1.9 /home/xxx/java/jdk/jdk-9.0.4
Then on the list will look as unclassified
sdk list java
| | 6.0.119 | zulu | installed | 6.0.119-zulu
Unclassified | >>> | 1.9 | none | local only | 1.9
=====================================================================
Then use it
sdk use java 1.9
All the JAVA JDK files will be extracted to candidates/java directory.
- You can extract the required jdk directory into
${SDKMAN_DIR}/candidates/java/. - In linux it will be in general
.sdkmanin/home/<user>/home/user/.sdkman/candidates/java - It will be shown as unclassified.
sdk list java ===== Available Java Versions================= Vendor | Use | Version | Dist | Status | Identifier ------------------------------------------------- Unclassified | >>> | dcevm | none | local only | dcevm-11.0.11_1
Use the following command to install it permanently:
sdk default java dcevm-11.0.11_1
Then set the JAVA_HOME path if required.
You may need to re-source sdkman-init:
source ~/.sdkman/bin/sdkman-init.sh
When I was in your situation, just after "installing" local versions to sdkman, use worked, but list and current didn't show the local versions and env init didn't populate .sdkmanrc with the version I selected with use. Re-sourcing sdkman-init fixed these issues.
Posting for posterity.
OK, I should have tried harder. I installed Java 19 with sdkman then the command "sdk default java [my old version]" switches back as required.