[SOLVED] The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt

Issue

I am using M1 Mac OS11.5.2.
I’ve already downloaded zulu.jdk and zulu.jre, in “/Library/Java/JavaVirtualMachines”.
I also exported the PATH.

echo export "JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.bash_profile

When I type

sudo apt update

I get this:

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

I hope some kind person could tell me the solution.

Solution

APT is for Linux

APT is for Linux, not macOS. Similarly, BSD has their own tools in Packages and Ports.

Homebrew

You can add a similar package-management tool to macOS developed by a third party: Homebrew.

I have not used Homebrew myself, but some folks are big fans.

For only installing JDKs, I would consider this tool to be overkill, and would recommend SDKMAN or manual installers as discussed further down. But if you might want to install other kinds of software besides just JDKs in this manner, then consider Homebrew.

SDKMAN

SDKMAN is a tool rapidly growing in popularity. As a collection of shell scripts, SDKMAN works across any Unix-oriented host OSes including macOS, BSD, Linux, and more.

SDKMAN works to manage the downloading, installing, and setting as default any of the many JDK offerings from a variety of vendors. This command-line tool has a simple well-defined API.

I only recently decided to avail myself of this tool. I expect this to be my new preferred way to manage my JDKs on my Macs and BSD servers.

IDEs

Some IDEs such as IntelliJ have a feature for downloading and installing a JDK. This is for the convenience of the Java programmer.

Manual installers

To install Java, I use an installer app for macOS from Adoptium or Azul Systems, or from any of the several other vendors providing distributions of Java such as BellSoft, Amazon, Microsoft, Oracle, SAP, Red Hat/IBM, Pivotal, etc.

To update I simply:

  • Delete the existing JDK found in /Library/Java/JavaVirtualMachines.
  • Run a freshly-downloaded installer.

This approach is a manual operation. And this requires the Mac’s admin password.

So for mass updates across many computers I can imagine that shell-scripting with SDKMAN would be a better solution. Also, some JDK vendors are releasing installers that can be controlled by a shell script.

Answered By – Basil Bourque

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5.CC BY-SA 3.0.CC BY-SA 4.0.

people found this article helpful. What about you?