2

It seems that /usr/bin/java exists on my mac even though java isn't installed.

$ which java
/usr/bin/java
$ java --version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

$ ls -lah /usr/bin/java
-rwxr-xr-x  52 root  wheel   164K Oct 18 05:36 /usr/bin/java

If there is no Java Runtime on my machine, then what is inside the /usr/bin/java file? Wouldn't it be better for /usr/bin/java to not exist when java is not installed?

I am pretty sure this is specific to mac, since I seem to remember when using other operating systems that when java isn't installed, the java command doesn't exist. (If that's not accurate, let me know and I can move this question to superuser.)

A good answer to this question will explain the difference and the relationship between the java command and the Java Runtime on macOS.

1
  • Do you get the same result if you issue the command directly/usr/bin/java --version? I wondering if you have an issue with your PATH.
    – Allan
    Commented Jan 27, 2023 at 21:28

1 Answer 1

7

/usr/bin/java is a program supplied by Apple that chooses one of several Java JREs to be used if any are installed.

If you do not have any installed, then the message shown will be displayed.

If you have any JREs installed then /usr/bin/java will run the one specified by the environment variable JAVA_HOME.

1
  • 1
    It's just a "java executable selector", similar to how /usr/bin/python-config is a Python selector.
    – smci
    Commented Jan 27, 2023 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .