Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDK is installed on mac but i'm getting "The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt." sudo apt update

Tags:

java

terminal

apt

I'm trying to run the command sudo apt update on my terminal in MacOS

I'm getting this message in response: 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 saw a similar question here, however even though I made sure to install the JDK like the solution suggested I'm still getting the same response.

I also tried pasting

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"

Into my .zshrc.save folder and had no luck.

When I run java -version in the terminal this is what I get back:

java version "15.0.2" 2021-01-19
Java(TM) SE Runtime Environment (build 15.0.2+7-27)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.2+7-27, mixed mode, sharing)
like image 818
User9123 Avatar asked Feb 18 '21 20:02

User9123


People also ask

Why does my Mac say unable to locate a Java Runtime?

The message “Unable to load Java Runtime Environment” means that the Mac computer cannot load JRE, either because it is out of date or (more usually) because it has not yet been downloaded and installed. It can also happen after the computer OS X has been updated, e.g. to 10.14 Mojave from 10.13 Maverick.

How do I find the path to JDK on Mac?

In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.


Video Answer


2 Answers

20 years ago, java shipped with a tool called apt: Annotation Processor Tool. This tool was obsolete not much later.

What that update-node-js-version is talking about, is a completely and totally unrelated tool: It's the Advanced Package Tool, which is a tool to manage installations on debian and ubuntu - linux distros. You do not want to run this on a mac, and the instructions you found are therefore completely useless: That is how to update node-js on linux. Your machine isn't linux.

Search around for answers involving brew, which is the go-to equivalent of apt on mac. And completely forget about java - this has NOTHING to do with java - that was just a pure coincidence.

like image 62
rzwitserloot Avatar answered Oct 21 '22 15:10

rzwitserloot


Install Homebrew on your Mac Machine

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

For the system Java wrappers to find this JDK, symlink it with

sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

If you need to have openjdk first in your PATH, run:

echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.profile

For compilers to find openjdk you may need to set:

 export CPPFLAGS="-I/usr/local/opt/openjdk/include"
like image 25
Nitin Jha Avatar answered Oct 21 '22 15:10

Nitin Jha