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.
Answer from LastStar007 on Stack Overflowsdkman! How to manage pre-existing JDK? - Stack Overflow
Getting started with SDKMAN! – Manage Java, Maven, Gradle versions with ease
sdk list java --all
How do I list all versions of Java available for install in sdkman? - Stack Overflow
Videos
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.
I put together a beginner-friendly guide on SDKMAN!, a super handy tool for managing parallel versions of Java SDKs, Maven, Gradle, and many other development tools right from your terminal.
If you've ever struggled with switching between Java versions for different projects, SDKMAN! can really simplify your workflow.
In the post, I cover:
What SDKMAN! is and why it’s useful.
How to install it.
How to install and switch between SDKs.
Tips for setting a default version.
Hope it helps someone!
As of https://github.com/sdkman/sdkman-candidates/blob/master/conf/routes java seems to be a special case.
At https://api.sdkman.io/2/candidates/java/linuxx64/versions/list?installed= I get a list of versions.
You can look up the platforms in https://github.com/sdkman/sdkman-candidates/blob/master/app/utils/Platform.scala
From what I have learned, this cannot be done; the API simply does not return the information. But I'd very gladly like to be proven wrong.
Apt-get won't overwrite the existing java versions.
To switch between installed java versions, use the update-java-alternatives command.
List all java versions:
update-java-alternatives --list
Set java version as default (needs root permissions):
sudo update-java-alternatives --set /path/to/java/version
...where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64).
Additional information:
update-java-alternatives is a convenience tool that uses Debian's alternatives system (update-alternatives) to set a bunch of links to the specified java version (e.g. java, javac, ...).
Use
sudo update-alternatives --config java
which lists all installed versions with current active one marked and provides dialog to switch:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path...
------------------------------------------------------------
0 /usr/lib/jvm/java-9-oracle/bin/java...
* 1 /usr/lib/jvm/java-7-oracle/jre/bin/java...
2 /usr/lib/jvm/java-8-oracle/jre/bin/java...
3 /usr/lib/jvm/java-9-oracle/bin/java...
Press <enter> to keep...[*], or type selection number:
Use
export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"
to set $JAVA_HOME from current active version
So, I have two different versions of Java in my system, 8 and 16. Depending on the project, I need to switch between the two. Right now, I need to use 16, but when I run java -version I see, I'm still using "1.8.0_202".
I have changed my JAVA_HOME variable to point to the location of Java 16. Do I need to uninstall Java 8 in order to use Java 16? I'd rather not do that.