Unable to locate an executable at "/Library/Java/JavaVirtualMachines/..." - java

I want to install an NPM express generator:
sudo apt npm install -g express-generator
It throws the following error:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home/bin/apt" (-1)
I installed Java in this path (it's not in the System/Library/ - maybe thats the issue?):
'MacintoshSSD/Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home'
My .bash_profile looks like that:
export JAVA_HOME=$(/usr/libexec/java_home)
If I check JAVA_HOME it looks fine:
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
.. and Java version:
java --version
openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
Any idea why it still can find an exectuable?
I an other thread I read about a possible conflict between the pre-installed macOS Java-Version and the Orcalce Java-Version enter link description here but I couldn`t work it out..
And could you explain to me the difference between java_home and JAVA_HOME?

Sorry, I just saw what's wrong...
There used to be an apt tool in Java, but it's gone now. Your mistake is using the linux command line. On many linux systems, another tool called apt is used for installing software.
Check the npm documentation on how to install npm on your Mac, as there are different ways to do it.
Once npm is installed, run sudo npm install -g express-generator (no apt here).
Explanation of the error message
The Java apt-tool was removed in JDK 8. But as JAVA_HOME/bin is normally not on your PATH on Mac, apple provides simple wrappers for all the commands under JAVA_HOME. There still is such a wrapper for apt that tries to run a program with the same name from your Java installation. That's why you get that error message.
conflict between the pre-installed macOS Java-Version and the Orcalce Java-Version:
Apple stopped pre-installing Java in macOS 10.7 so this should not be an issue.
difference between java_home and JAVA_HOME:
JAVA_HOME is an environment variable that points to your Java installation. java_home is a utility program in macOS that makes it easier to correctly set up your JAVA_HOME by listing installed Java versions and the values to use for JAVA_HOME.

Related

Windows WSL Ubuntu 22 doesn't recognise the upgraded Java version I installed on Windows

I'm a newbie and am confused over the setup for one of my cs courses.
I originally have Java 8 in both Windows and Ubuntu, but then I realised that I need to use jshell for testing in Ubuntu as well, which is only available for Java 9 and higher.
Hence I downloaded the newest Java 19 on my windows but Ubuntu doesn't recognise it and still use Java 8.
How can I go around to update the Java in Ubuntu as well without having to redownload it again?
Below is on my Ubuntu terminal:
hejin#LAPTOP-8I6A5M2K:~/cs2030s$ java.exe -version
java version "1.8.0_351"
Java(TM) SE Runtime Environment (build 1.8.0_351-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.351-b10, mixed mode)
hejin#LAPTOP-8I6A5M2K:~/cs2030s$ javac.exe -version
javac 1.8.0_351
hejin#LAPTOP-8I6A5M2K:~/cs2030s$ jshell.exe
jshell.exe: command not found
hejin#LAPTOP-8I6A5M2K:~/cs2030s$ jshell
Command 'jshell' not found, but can be installed with:
sudo apt install openjdk-11-jdk-headless # version 11.0.17+8-1ubuntu2~22.04, or
sudo apt install openjdk-17-jdk-headless # version 17.0.5+8-2ubuntu1~22.04
sudo apt install openjdk-18-jdk-headless # version 18.0.2+9-2~22.04
sudo apt install openjdk-19-jdk-headless # version 19.0.1+10-1ubuntu1~22.04
(to be honest I don't know why it seems others can do fine with just java Hello.txt and javac Hello.txt but I have to add .exe at the back.
And below is my command prompt terminal:
C:\Users\User>java -version
java version "19.0.1" 2022-10-18
Java(TM) SE Runtime Environment (build 19.0.1+10-21)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)
C:\Users\User>javac -version
javac 19.0.1
C:\Users\User>jshell -version
jshell 19.0.1
C:\Users\User>jshell
| Welcome to JShell -- Version 19.0.1
| For an introduction type: /help intro
jshell> 1 + 1
$1 ==> 2
jshell>
I am confused over what some answers I searched online talked about changing the environment variable path as well... When I checked the advanced system settings the jdk19 path seems already there.
screenshot of my system settings environment variables
Here are a few things to check with your path dealings Windows -> WSL Ubuntu. On Windows you can confirm where java is found by:
echo %Path%
=> should print list of colon separated folders on your path example:
C:\java\jdk-20\bin;etc
which java.exe
=> should print name of java.exe found inside %Path% example:
C:\java\jdk-20\bin\java.exe
When you run wsl.exe to load WSL Linux distribution the Windows Path is translated to Linux semi-colon separated PATH without drive letters:
C:\java\jdk-20\bin;etc => /mnt/c/linux/jdk-20/bin:etc
On WSL Linux check where it looks up PATH:
echo $PATH
=> should print list of colon separated folders on your path:
/mnt/c/linux/jdk-20/bin:etc
=> its likely you have 2 JDK in Linux PATH
which java.exe
=> finds "java.exe" of the first JDK in the Linux PATH
Have a look at any WSL Ubuntu bash profiles which may also override PATH in WSL to see what causes the 2nd JDK in path - typically ~/.bashrc or ~/.profile and fix so the later JDK19 is first or only JDK one resolved.
Note that fixing WSL Linux to access Windows JDK introduces a new issue if you actually need Linux JDK, but you could always use "java" vs "java.exe" from WSL if you need to work in both JDK platforms from Linux.

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

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)
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.
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"
The below commands worked for me.
First, install the homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then set the Android Studio Java path to the Home(If you have Android Studio). If not then you take the respective Java path & export it to the JAVA Home path.
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home

gradle on command line [duplicate]

I'm working on MacOS and just starting with react-native.
One of the first steps to get started is to run: react-native run-android or react-native run-ios. But I'm getting this error:
react-native run-android
Result:
Scanning folders for symlinks in /Users/ric/myprojs/albums/node_modules (6ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '9.0.1'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
This is what I get when I run java --version:
java --version
Result:
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
mbp:albums ric$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Edit
My javac version:
javac --version
Result:
javac 9.0.1
Any idea on how to fix this?
In your PROJECT_PATH/android/gradle/wrapper/gradle-wrapper.properties file, update your distributionUrl to the following:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
See related gradle distributions documentation
Really the fastest way to get around this error is to use JDK 8. Except when you really need to use JDK9.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Don't forget to change your enviroment variable JAVA_HOME to the new JDK version!
Make sure that you have JDK8 installed and then set JAVA_HOME into JDK8
for example:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
or use .bash_* files to set this variable
vi ~/.bash_profile
Then add the following lines:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Now source the file to make the above changes effective in the current shell:
source ~/.bash_profile
On MacOS, I ran the following commands:
brew cask uninstall java
brew tap caskroom/versions
brew cask install java8 "or just brew cask install java to install latest version"
I was getting this error, but for a more recent version of Java - 10.0.2.
To fix my error, I followed the steps mentioned by #Blacktoviche in this Github issue: https://github.com/facebook/react-native/issues/17688
When I opened the android folder inside my project via Android Studio, I was prompted with Android Gradle plugin update recommended. At the time, I was following a slightly outdated tutorial that told me to click Don't remind me again for this project.
However, as #Blacktoviche recommended in the github issue linked above, sometimes it's necessary to update the Gradle plugin. After updating, I also had to click Install Build Tools 27... and sync project (I don't remember the exact version).
After I followed these steps, I was able to successfully run my react native app on the Android Studio emulator.
Hope this helps someone!
---- December 2018 --- keep attention ---
React Native does not work with Java versions higher than 8, so you need to uninstall your 9.0.1 version. To do so, execute the following commands:
cd /Library/Java/JavaVirtualMachines/
ls -l
Identify the folder containing your Java Version, then remove it
sudo rm -rf jdk.x.x_xxx.jdk
After that you can download and install java 8 from oracle again. Refer to jdk8 download page
If you are using windows; Make sure you add your jdk path to the Environment path variable.
Then open your android folder from your react native project into android studio. It will update necessary things for you automatically.
I usually get this error when I forget to build the project using Android Studio. A simple sync and upgrading Gradle will do the work.
I solve this by downgrading my JDK to 8.
On Ubuntu, you should run these command lines in the terminal:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default

error in setting java home environment variables ubuntu

i am new to ubuntu .initially i installed java in Ubuntu.
But i haven't set any envionment variables
After that installed maven build tool to build java package.when i compiled with build tool it shows some error says generic supports after 1.3 packages.
so i realize it JDK runs with 1.3. so i need set java environment variables for latest version
so in my Terminal java -version shows
beeshma#ubuntu:~$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
and i set java environment variables in through below steps
[https://askubuntu.com/questions/277806/how-to-set-java-home][1]
sudo gedit ~/.bashrc
Now go to end of file and add the following lines:
export JAVA_HOME=/path/to/jdk/folder
#usually /usr/java/jdk or /usr/lib/java/jdk
export PATH=$PATH:$JAVA_HOME/bin
Now in terminal type:
sudo source ~/.bashrc
This will make it appear on every terminal if open.
Now you can cross check it by typing following line in terminal
$echo $PATH
/usr/java/jdk1.7.0_45//bin:/home/beeshma/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/java/jdk1.7.0_45//bin
What my question when i execute mvn --help
Fallowing error is coming
beeshma#ubuntu:~$ mvn -version
Error: JAVA_HOME is not defined correctly.
**We cannot execute /usr/java/jdk1.7.0_45//bin/java**
Try changing your export to:
export JAVA_HOME=$(/usr/java/jdk1.7.0_45)
Two things:
Try if /usr/java/jdk1.7.0_45//bin/java is indeed present.
See if the beeshma user has the permissions to 'execute' java.
Bonus: remove the trailing / in your JAVA_HOME value.
You can install the JDK with the following command:
$sudo apt install default-jdk
The above command also sets the java environment variable automatically

JRE error when trying to install Matlab Compiler Runtime

Once again, I spent much time trying to get something to work without success.
I want to install MATLAB Compiler Runtime on my Ubuntu 13.04, where there is no MATLAB installed.
Here's what I did:
I downloaded the 64-bit Linux version R2012b(8.0) off of
http://www.mathworks.com/products/compiler/mcr/index.html?s_cid=BB.
Then, I switched into the folder and tried to install via
sudo ./install just to receive the following message:
Error: Cannot locate Java Runtime Environment (JRE).
The directory /home/konni/Downloads/MCR_R2012b_glnxa64_installer/sys/java/jre/glnx86/jre does not exist.
And, it does not exist indeed, but there exists a folder with "glnxa86" instead of "glnx86". I wouldn't just want to rename it, though.
I do have a JRE installed on my machine, btw:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)
I have absolutely no clue what to do. The problems I found using google didn't quite help me, either...
Maybe you have an idea?
I'd greatly appreciate any help! :-)
If the only problem is finding the JRE, then the command line switch -javadir will get you done:
./install -javadir /usr/lib/jvm/java-7-openjdk-i386/jre/
I had the same problem recently when installing a software that required a 7.13 MCR on an Ubuntu 17.10.
In this
https://www.linuxquestions.org/questions/linux-newbie-8/matlab-7-5-compiled-runtime-for-64-bit-linux-installation-no-jre-error-838281/
I found that the 32 bit version installs fine, and it did, but obviously, that didn't solve my problem.
However, I found a way to do it. The trick is that the installer needs the old JRE (1.5) and will not work with JDK 8.
So the first step is to run
./MCRInstaller.bin -is:extract
this will create a directory called istemp... something, for me istemp23732345211606.
ls
jre1.5.0-linux-amd64.bin JVMNotFound.txt setup.jar Verify.jar
It is tempting to run the setup.jar directly, do try, but with Java 8, I only got the following error message:
Could not load wizard specified in /wizard.inf (104)
But perhaps it will work for you. People who get the above mentioned error with wizard.inf should look further, because the installer needs JDK 5 to run.
I chose not to use the bundled version but downloaded the JDK 5 from Oracle. The bundled version might work as well - I did not try.
You can download JDK 5 from here:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html#jdk-1.5.0_22-oth-JPR
Extract the downloaded archive (chmod +x the bin and run), then copy the files to /usr/lib/jvm/java5
Rename the jdk1.5.0_022 or anything to jdk1.5.0 to make it simple.
Fix attributes:
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/java5/jdk1.5.0
Then run:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java5/jdk1.5.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java5/jdk1.5.0/bin/javac" 1
Now chose the jdk 5 as default
sudo update-alternatives --config java
And selecting the appropriate option.
Check that it worked
java -version
You should see something like this:
java version "1.5.0_22" Java(TM) 2 Runtime Environment, Standard
Edition (build 1.5.0_22-b03) Java HotSpot(TM) 64-Bit Server VM (build
1.5.0_22-b03, mixed mode)
Now you can run the setup.jar file in the extracted directory (istemp...)
sudo java -jar setup.jar
I recommend that you chose a contemporary java by running
sudo update-alternatives --config java
again.
When running the installer.sh, use the command line option "-is:javahome [path to your java jre folder]".
For instance, I installed below a java 8 jre on an old matlab compiler 2007b as follow:
sudo /opt/installer.sh -console -is:javahome /usr/lib/jvm/java-8-openjdk-amd64/jre/
I had same problem. The problem is you are installing 64-bit matlab on 32-bit ubuntu. use 32-bit matlab and install in ubuntu 32-bit. use 64-bit matlab and install in ubuntu 64-bit. Please like the answer if it was helpful.

Categories

Resources