I just happen to get that error, on Manjaro ..after an update of the S.O., so the error is the /usr/bin/java now points to the default java installed on the update.
So i just removed all Java versions installed on the updates cause I need only to use the sdkman.
Copysdk home java 8.0.232.hs-adpt
With this i can see where are the candidates on my case:
Copy/home/xxxx/.sdkman/candidates/java/8.0.232.hs-adpt
So after removed all java: i run java -version i found there is no java anymore.
So i force update sdkman
Copysdk selfupdate force
Then after install
Copysource "$HOME/.sdkman/bin/sdkman-init.sh"
And to be sure i ran :
Copyls -al /usr/bin/java
lrwxrwxrwx 1 root root 37 may 16 2020 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java
and now it points to where sdkman supposed to:
And thats it now i can change versions again with sdkman.
Copysdk use java 11.0.5.hs-adpt
Answer from cabaji99 on Stack OverflowI just happen to get that error, on Manjaro ..after an update of the S.O., so the error is the /usr/bin/java now points to the default java installed on the update.
So i just removed all Java versions installed on the updates cause I need only to use the sdkman.
Copysdk home java 8.0.232.hs-adpt
With this i can see where are the candidates on my case:
Copy/home/xxxx/.sdkman/candidates/java/8.0.232.hs-adpt
So after removed all java: i run java -version i found there is no java anymore.
So i force update sdkman
Copysdk selfupdate force
Then after install
Copysource "$HOME/.sdkman/bin/sdkman-init.sh"
And to be sure i ran :
Copyls -al /usr/bin/java
lrwxrwxrwx 1 root root 37 may 16 2020 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java
and now it points to where sdkman supposed to:
And thats it now i can change versions again with sdkman.
Copysdk use java 11.0.5.hs-adpt
For me, the problem was the ending of .bashrc. I know, it explicitly says there "THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!", but I still decided to ignore that and wrote a few of my own lines after those ones 🤡. When I made sure the sdkman's lines were indeed at the very end of the file and after running sdk selfupdate force, setting the version started working properly across different terminals.
How do you change java version using SDKMAN without needing to close Intellij IDEA first? - Stack Overflow
How do I change default version of java from my terminal?
Easily switch between java versions with SDKMAN! and 'j'
Switching versions of Java on Mac OSX
Videos
After some additional effort to figure this out, it turned out to be an easy fix. SDKman stores the JDKs in this folder:
C:\Users\yourUserName\.sdkman\candidates\java
When you issue the command
sdk default java 8.322.06.2-amzn
it copies the JDK from the java 8 folder
C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn
and pastes it into the current folder.
C:\Users\yourUserName\.sdkman\candidates\java\current
The idea is that you point your pc to the "current/" directory so that when you change java version with SDKman, the pc environment variable never needs to be updated.
But for the ide, instead of pointing it to the "current/" directory, you can point it directly to the JDK folder
C:\Users\yourUserName\.sdkman\candidates\java\8.322.06.2-amzn
You can specify the JDK for each project, P1 and P2, separately. So even if you change java version with SDKman, that only effects the "current/" directory, which the ides are no longer pointing at.
Since I did this, I dont have to change java version if I want to switch working on my java 8 project to working on my java 11 project. And that means I dont have to close my java 8 project to open my java 11 project. I can have them both open at the same time, and switch between them easily.
Inside IntelliJ versus outside IntelliJ
- For running a project from within IntelliJ, you specify which JDK to use by configuring within IntelliJ.
- The current default JDK set by SDKMAN! only applies to Java apps being executed on their own, outside IntelliJ.
Unfortunately, configuring which JDK to run your app within IntelliJ is complicated and confusing, requiring you to go spelunking through various buried panels.
These panels include some for the JDK, and some for the language level (which version of Java to target):
- File | Project Structure | Project Settings | Project | SDK … and Language Level.
- File | Project Structure | Project Settings | Project | Modules | Language Level.
- Settings | Build, Execution, Deployment | Compiler | Java Compiler | Per-module bytecode version.
There may be others I don't recall at the moment. Search Stack Overflow to learn more.
If you are building a Web app in IntelliJ Ultimate edition, and running that app from within IntelliJ via an external application server such as Tomcat, Jetty, Glassfish, OpenLiberty, etc., then you need to also specify in another IntelliJ panel which JDK should be used to launch that app server.
If using Maven or Gradle, you need to specify language level there too.
Currently, when I input "java -version", I get an output of "20.0.1". When I input "/usr/libexec/java_home -V", It says I have 20.0.1, 17.0.9, and 11.0.9.
When I input "export JAVA_HOME=$(/usr/libexec/java_home -v 17.0.9);" to change the version and run "java -version" again, It shows as 17.0.9.
The problem is when I close my terminal and check my java version, it returns back to version 20. How do I permanently change my default java version. Thanks.
https://joerg-pfruender.github.io/software/java/2022/12/30/sdkman_j.html