1

While I have some experience in Python and JavaScript, I am new to Java and am trying it out for the first time. To get started, I went to http://www.java.com, downloaded the dmg there, and then used the package it gave me to install Java. After doing so, I received confirmation that Java had been installed successfully and I closed and trashed the dmg and package. Afterwards, I hopped on my terminal (I am using a Mac running on MacOS Monterey) and tried to use javac on a script I wrote. I received the following error message:

The operation couldn’t be completed. Unable to locate a Java Runtime that supports javac.
Please visit http://www.java.com for information on installing Java.

I went online and did some typical troubleshooting searches. First, I found a site suggesting that I create an environment variable $JAVA_HOME and set it equal to $(/usr/libexec/java_home) in .zshenv (yes, I use zsh not bash). I followed this instruction and when I run echo $JAVA_HOME I get /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home. However, running javac still did not work. Once more, I went online and this time, I found the suggestion of adding javac to $PATH. So I went into .zshenv and added usr/bin/javac to $PATH (the $PATH export line now looks like this: export PATH="/Users/[redacted]/Library/Python/3.8/bin:/usr/bin/javac:$PATH"). This alteration was confirmed when I exited an reentered terminal and ran echo $PATH. However, once again, running javac yielded the same error. I feel as if I am facing what must be a pretty common and easily fixable issue, but yet, I haven't yet been able to find a solution that works despite perusal of several other StackOverflow posts and tech articles. Still, I know I'm probably missing something simple, and if this is a duplicate of another question, please link that question in a comment, and I'll take this one down. Thanks!

Zarquon
  • 146
  • 8
  • 4
    I think you downloaded just the Java Runtime Environment, not the Java Development Kit (JDK). Go back to https://www.java.com/en/ and click on Java SE Development Kit – tgdavies Dec 29 '22 at 05:13
  • 2
    The "recommended" download on that website seems to be Java 8, which is ancient. Make sure you install a somewhat recent version. Either 17 (LTS) or 19 (latest) should be good. – Siguza Dec 29 '22 at 05:18
  • Does this answer your question? [The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt](https://stackoverflow.com/questions/69508381/the-operation-couldn-t-be-completed-unable-to-locate-a-java-runtime-that-suppor) – user1934428 Dec 29 '22 at 09:49
  • Also, thanks @Siguza - I'm not sure why the site that the error message references suggests installing an old version of Java, so thank you for pointing that out to me, as I would have been stuck with version 8 if you hadn't. – Zarquon Dec 29 '22 at 16:06
  • @user1934428, the post you linked did not quite answer my question - the issue there was that the post owner did not realize that `apt` is a linux command not available on macOS and was not an issue with not having JDK installed. Although there probably is one out there, since I have not yet seen a similar enough post, I'm going to continue to keep this up until I see one similar enough. – Zarquon Dec 29 '22 at 16:11
  • Right. OTOH, you did not specify which OS you are using either .... – user1934428 Dec 29 '22 at 16:13
  • @user1934428 I did, actually. It's a little buried in there, but in the first paragraph I wrote that "I am using a Mac running on MacOS Monterey" – Zarquon Dec 31 '22 at 16:09
  • Ah, right. BTW, in this case I recommend using the tag _macos_. Also, since your question is not that much about programming, but to get Java properly running, I think it is off-topic here, but would be on-topic on [su] or - since it is about the Mac - [AskDifferent](https://apple.stackexchange.com/). – user1934428 Jan 01 '23 at 08:25
  • if you're going to do this by adding javac directly, don't PATH it, just use an alias. But installing java on macos is basically a job for `brew`, not "the java installer". – Mike 'Pomax' Kamermans Jan 03 '23 at 02:34
  • Yeah, it probably would have been easier to use HomeBrew. I just wish that the error message that it gave me would have pointed me in that direction instead of towards https://java.com. – Zarquon Jan 03 '23 at 02:37
  • Also, @user1934428, per your suggestion, I added the tag `macos`. I also agree, looking at Super User, that the question would be more on-topic over there. However, I've never used Super User, and since this question already has an answer over here, I don't feel much motivation to figure out how to transplant it over there for the marginal benefit that would yield. At the moment, I'm just going to let this be - but of course I'll take it down should I be made aware of a duplicate. – Zarquon Jan 03 '23 at 02:43
  • @Siguza - I would not recommend to a beginner to use anything other than a current LTS release; i.e. 8, 11 or 17. The 19 release will be EOL within 6 months!! The non-LTS releases are for folks who enjoy tap-dancing on the bleeding edge need them. – Stephen C Jan 03 '23 at 02:45
  • @Zarquon it can't, because it can't point to third party "I have no idea if this will still exist by the time you run me" websites or services. I only knows java.com is its official home. Most installs are universal brew/asdf jobs, irrespective of what the tool itself claims =) – Mike 'Pomax' Kamermans Jan 03 '23 at 02:55

0 Answers0