kkkk
kkkk

Reputation: 329

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

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.

Upvotes: 12

Views: 38988

Answers (2)

Ryan
Ryan

Reputation: 21

The file in /usr/bin/apt on macOS (still there as of macOS 14 Sonoma) has nothing to do with the Debian package manager. See:

https://stackoverflow.com/a/66267603/9470779

Upvotes: 0

Basil Bourque
Basil Bourque

Reputation: 340070

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.

Here is a question that gives instructions for how to install Java from Homebrew on macOS: How to brew install java?

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.

Upvotes: 8

Related Questions