I seem to have a bit of a mess. At the terminal, I get:
> java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
Which is good (I'm trying to get Java 8 running). which java gives /usr/bin/java and:
> ls -al /usr/bin/java
/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
Here I think I see where Java is actually installed.
Now my problem is that when I code a simple Java program and type:
System.out.println( System.getProperty("java.version") )
System.out.println( System.getProperty("java.vendor") )
I get the output:
1.6.0_65
Apple Inc.
So what am I doing wrong?
p.s. I am using Eclipse and while I can manually select a different JDK to use there, I would like Java 8 to be a system default. For example, I recently downloaded Eclipse Luna which does not open, giving the following error message:
Version 1.6.0_65 of the JVM is not suitable with this product.
Check the java home using:
/usr/libexec/java_home
Move to that directory:
cd /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
cd bin
java -version
To switch the jdk 8 you will need to modify /usr/libexec/java_home to correctly point to java 8.
Related
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.
I have a problem with running Netbeans for Java development..
When I try to run it I get
I checked the config located in <netbeans_dir>/etc/netbeans.conf and found following setting:
netbeans_jdkhome="/usr/"
So, I checked java and javac:
>>java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
>>whereis java
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
>>javac -version
javac 1.8.0_151
>>whereis javac
javac: /usr/bin/javac /usr/share/man/man1/javac.1.gz
So I updated netbeans_jdkhome to /usr/bin/javac. Now, when I try to run Netbeans I get
Cannot find java. Please use the --jdkhome switch.
I also tried to reinstall Java according to this instruction but once I did and changed jdkhome to /usr/lib/jvm/java-8-openjdk I still get Cannot find java.
What should I enter to run Netbeans properly?
Tools -> Java Platforms -> Add platform should display something like this:
Notice that Platform folder has small rectangle that indicates it can be chosen.
I use macOS Sierra. When I do:
java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468-11M4833)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
it seems that my java version is 1.6.0.
But when I look at System Preferences I find that my version is Java 8 Update 144. I want to use an R package that needs Java >=8.0. What have I done wrong?
The Java found in your command line is the one used to compile when using command line, first, try export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) then check if the correct version shows up using java -version if not reinstall the newest java and run the command again
Trying to install Sencha Command 3.1.1 on my iMac (10.8.3). The installer is saying:
The installer could not find a valid Java(tm) on this machine.
Supported versions: Vendor : Any min. 1.6.0 max. any
Following another Stack Overflow thread, I tried linking /usr/bin/java to /Library/Internet Plugins/JavaAppletPlugin.plugin/Contents/Home/bin/java. Now, I get this on the command line:
~ 🍔 java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
So that looks good, but the installer still complains that it cannot find Java. Why can't it?
What eventually fixed this for me, after consulting with Sencha support, was installing the full JDK rather than just the JRE. I don't know exactly why this fixed it, or what the root cause was, but now Command installed successfully and is working fine.
I had JDK installed, but one thing worked for me was exporting $java_home/bin:
export PATH=$JAVA_HOME/bin:$PATH
I have a MacBook Pro running Snow Leopard; how can I see what version of the Java SDK is installed on my Mac?
Open a terminal and type: java -version, or javac -version.
If you have all the latest updates for Snow Leopard, you should be running JDK 1.6.0_20 at this moment (the same as Oracle's current JDK version).
In /System/Library/Frameworks/JavaVM.framework/Versions you'll see all the installed JDKs. There is a symbolic link named CurrentJDK pointing the active JDK.
The simplest solution would be
open terminal
$ java -version
it shows the following
java version "1.6.0_65"
Stefan's solution also works for me. Here's the exact input:
$ cd /System/Library/Frameworks/JavaVM.framework/Versions
$ ls -l
Below is the last line of output:
lrwxr-xr-x 1 root wheel 59 Feb 12 14:57 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
1.6.0.jdk would be the answer
On modern macOS, the correct path is /Library/Java/JavaVirtualMachines.
You can also avail yourself of the command /usr/libexec/java_home, which will scan that directory for you and return a list.
Which SDKs? If you mean the SDK for Cocoa development, you can check in /Developer/SDKs/ to see which ones you have installed.
If you're looking for the Java SDK version, then open up /Applications/Utilities/Java Preferences. The versions of Java that you have installed are listed there.
On Mac OS X 10.6, though, the only Java version is 1.6.
Run this command in your terminal:
$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Cristians-MacBook-Air:~ fa$