Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

wsl: 'which java/whereis java' give wrong information

I have installed wsl2,and then installed jdk 17. Now I want to configure JAVA_HOME.
When I do:

$ which java
/usr/bin/java
$ whereis java
java: /usr/bin/java

But I don’t see any java folder in /usr/bin.

Instead, I found java in /usr/lib/jvm:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ pwd
/usr/lib/jvm
$ ls
java-1.17.0-openjdk-amd64  java-17-openjdk-amd64

Why so?

>Solution :

Because java isn’t a folder, it’s a binary, and probably a link to one of the binaries in jvm directory. You can check where the Java application points to by using ls -al /usr/bin/java

JAVA_HOME shouldn’t point to the Java binary, but to one of the directories you’ve listed in the second example, so something like JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64.

I’d recommend having a look at jenv btw, it helps a lot in switching JDKs should you need it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading