On a desktop with a dual boot I currently have Java JDK 8 in the Linux (Mint) system
chris#M17A ~ $ sudo apt install default-jdk
...
default-jdk is already the newest version (2:1.8-56ubuntu2).
...
chris#M17A ~ $ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
But I'm sure that in fact 1.8.0_171 is not the latest version, even of Java 8! If I want to change to 1.11.xxx, which seems to be the latest LTS release (for Oracle non-OpenJDK at least), what should I do? Do I have to manually download something, or use a PPA? How can I be sure my Linux OS is using the version-11 JRE and the version-11 JDK?
I've also never quite understood either about the versioning of the JRE side of things and how this corresponds to the JDK being used. On my Windows machine (W10) I am using a Java 9 JDK but a Java 8 JRE (I think). Is this a bad thing to do?
This question says there is no such thing in Windows as a Java 11 JRE, although there is a Java 11 JDK. Is that a problem in W10? Would it be a bad idea to use an JDK 11 with a JRE 8?
I also simply don't understand why it is not possible read somewhere about the "latest JRE" or "latest stable JRE". These do not appear to be coupled one-to-one with the latest JDK as far as I can make out but I'm having difficulty obtaining clarity about all this.
I also have some difficulty understanding whether I should opt for OpenJDK or the other JDK (they're both Oracle so I don't know how to refer to the non-OpenJDK one... "commercial JDK"?). But unlike the above difficulties there are lots of explanations out there. I am mainly looking for "latest stable release" hopefully with LTS. Seems like "Commercial JDK" version 11 might be the way to go...
Java 8 is the default JDK (recommanded) for your System.
According to this, you need to add the repository of openjdk using this command:
sudo add-apt-repository ppa:openjdk-r/ppa
After that you need to update you index using
sudo apt-get update
If you want to install jdk 11 you can do:
sudo apt-get install openjdk-11-jdk
[Hint]
default-jdk is the default jdk. This means that, if this is up-to-date, you have the recommanded/default version of a jdk.
Also, openjdk seems to be recommanded for linux
When trying to compile an JavaFX application in the environment:
java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
I get the error-message:
cannot access javafx.event.EventHandler
[ERROR] class file for javafx.event.EventHandler not found
I tried to find a solution by following these links:
how to add javafx dependencies in maven with java 10
https://mvnrepository.com/artifact/org.openjfx/javafx/11
Maven project with JavaFX (with jar file in `lib`)
https://github.com/javafx-maven-plugin/javafx-maven-plugin
https://askubuntu.com/questions/1091157/javafx-missing-ubuntu-18-04
https://unix.stackexchange.com/questions/505628/add-openjfx-class-path-in-debian-for-java11
https://askubuntu.com/questions/609951/javafx-is-not-on-the-default-classpath-even-with-oracle-jdk-1-8
Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?
http://can4eve.bitplan.com/index.php/JavaFX
The most promising actions where to
install openjfx with apt install openjfx
set the JAVA_HOME environment variable to /usr/lib/jvm/java-8-openjdk-amd64
But the error persists.
What needs to be done to get OpenJDK 8 and JavaFX working on Ubuntu 18.04.2 LTS?
The hint from
https://github.com/JabRef/help.jabref.org/issues/204
helped. The commands:
apt purge openjfx
apt install openjfx=8u161-b12-1ubuntu2 libopenjfx-jni=8u161-b12-1ubuntu2 libopenjfx-java=8u161-b12-1ubuntu2
apt-mark hold openjfx libopenjfx-jni libopenjfx-java
fixed the problem. Many thanks to https://github.com/Druidefix for this. (If you'd like to answer this yourself I'll happily delete my own answer ...)
What I did was build it from source. The instructions here on the OpenJDK wiki worked for me. Once I built it, I had to put the jars in the right place, like this other stackoverflow post talked about.
cd build/sdk/
sudo cp -R rt/lib /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/
sudo cp ./lib/ant-javafx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/
sudo cp ./lib/javafx-mx.jar /usr/lib/jvm/java-8-openjdk-amd64/lib/
After that I was able to compile my project!
Use Oracle JDK (even if only as a temporary workaround)
For any learners looking for a bit of basic practice with javafx, installing Oracle's Java 8 (which has javafx built-in) might be a better solution then messing about with open packages. There are great instructions here
You can continue efforts getting openjfx installed, but this will keep your learning going.
This has already been suggested by aran in a comment to the OP, please consider upvoting that comment.
I am new to Linux and installed Ubuntu. Fine. I gone through the basics of file system and basic things to know.
I installed Jdk1.7. by downloading the related .rpm file from oracle website. I installed Eclipse. I gave the the installed jdk1.7 jre folder in the eclipse project classpath.
But it is not identifying that and a simple java code is not getting compiled.
In one of the forums I found that we should use openjdk for linux distributions.
could someone explain me Why is that? and am I doing anything wrong by installing the jdk7 from oracle website in these linux distributions?
What difference they make?
Thanks
No, you don't have to use openjdk, any jdk should work fine. You say that you gave path to the jre in the jdk, not jdk itself? JRE has no compiler, JDK has.
Try
sudo apt-get install openjdk-6-jdk eclipse
and see if it helps.
The Openjdk or icedtea or ... are JRE or JDK which try to be as open as possible. Oracles JDK/JRE is not Open enough in respect to the open source community, which is something the usual Linux user doesn't want in its Linux distribution as default implementation.
For a to releasing product you should specify the supported/tested Java implementation. There can be difference for example in performance or in tooling.
For developing with eclipse you don't necessarily need a JDK, because eclipse has its own Java Compiler. But it is recommended to use a JDK. It has nice tools and for some projects you need a JDK.
(The oracle jdk (and jre) are working just fine (at the current u05 release)).
Given that I've understood where you unpacked/put/installed the jdk (check the path), the following commands should fix a lot for you.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.7/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.7/bin/javac" 1
(
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.7/bin/javaws" 1
)
sudo update-alternatives --config java
sudo update-alternatives --config javac
Hopefully this should make ubuntu take care of your java specific env. variables.
I would like to know which version of java is installed on my ubuntu system.
The java -version command shows:
cmdprompt$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build
1.6.0_20-b02)
Java HotSpot(TM) Client VM (build
16.3-b01, mixed mode, sharing)
However the following cmd shows 2 Java versions installed? What are these?
cmdprompt$ ls -l $(type -path -all java)
lrwxrwxrwx 1 root root 22 2010-02-28 14:21 /usr/bin/java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 15 2010-06-29 22:36 /usr/lib/jvm/java-6-sun/bin/java ->
../jre/bin/java
How do I ensure there is ONLY ONE version of JAVA is installed - so that there are no build conflicts?
The alternatives directory contains links pointing to your preferred alternatives. (This makes it really easy to switch between preferred versions.)
To me it looks like you only have one version installed, and that this version is pointed to by /etc/alternatives/java.
How do I ensure there is ONLY ONE version of JAVA is installed - so that there are no build conflicts?
Well, first of all, I doubt that you'll be running into trouble with build-conflicts. But to ensure that you only have one version of java installed, you could list all installed packages called something with java like this:
dpkg --get-selections | grep -i java
and then remove the packages you don't want to have installed, using apt-get remove pkgname.
Ubuntu supports several different possible installations of Java by a common trick, namely symlinks. If you type which java it will tell you that "java" resolves to "/usr/bin/java" (where Java is supposed to be installed), which in turn points to /etc/alternatives/java which is a symlink that is automatically updated via the update-alternatives command. This command may be used to, for example, switch between Sun's Java implementation and the Open JDK version of Java. There won't be any conflicts, since they each occupy distinct locations and have distinct paths, and the symlink (where the system expects to find Java) may be easily updated to switch to whichever one is to be used.
You can use update-alternatives to see which version of Java is currently selected. For example:
sudo update-alternatives -l
The command above will tell you which "alternatives" have been selected for various tools.
I have always had about a dozen version of java installed and I have never got build conflicts. A build should only use one version of Java at a time. All versions of Java 6 are basically compatible so even if you mixed them you wouldn't see an issue.
If you tried to use a class compiled with Java 6 in a Java 5.0 compiler you would get a error which would make it obvious you have a version problem. However, if you set the '-target 1.5' option you can mix Java 5.0 and 6 compilers as well.
In short, I wouldn't worry about it unless you know you have a problem.
I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp.
I looked for a Mac version, but I'm a bit surprised to only see downloadable versions for Linux, Windows and Solaris...
Here's the message for Mac:
"Apple Computer supplies their own version of Java. Use the Software
Update feature (available on the Apple menu) to check that you have
the most up-to-date version of Java for your Mac."
OK BUT... when I update Java with Mac I have a JRE and not a JDK...
I don't understand why a JDK version doesn't exist that is easily downloadable/installable (like a jar to unzip?) for Mac...
In a comment under #Thilo's answer, #mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:
export JAVA_HOME=`/usr/libexec/java_home`
This will dynamically assign to JAVA_HOME the location of the first JDK listed in the "General" tab of "Java Preferences" utility.
See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html
EDIT:
If you prefer parentheses to backticks for command substitution, this also works:
export JAVA_HOME=$(/usr/libexec/java_home)
As the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).
See: http://developer.apple.com/java/
NOTE This answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download page on Oracle's website now.
For people using any LION OS X 10.7.X
They uploaded Java SE 6 version 1.6.0_26 available here
http://support.apple.com/kb/dl1421
I bought a MacBook Pro yesterday (Mac OS X v10.8 (Mountain Lion)) and there is no JDK installed by default...
As well as javac, I also found it didn't have packages such as SVN installed. It turns out you can get everything from the Apple developer page (you will need to register with your AppleID). SVN is part of the "Command Line Tools" package.
This is what happens on a fresh MacBook:
Hopefully this will help out other newbies like me ;)
The explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library and Mac's JDK doesn't provide it:
(Cf. http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html)
tools.jar does not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jar need to be rewritten accordingly.
It sucks!
The easiest way is to use Homebrew.
Install Homebrew and then:
brew tap caskroom/versions
brew cask install java7
You can list all available versions using the following command:
brew cask search java
Mac comes with the JDK, for more information check:
http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html
Compiling with -source 1.5 -target 1.5 (in a JDK 6 environment) will honor only language elements that were in 1.5 and prior. Great. But there were no language changes in 6 anyway. Problem with this approach (on Mac with 1.6) is that using classes that came AFTER 1.5 will still compile because they exist in the rt.jar. So one could run in a 1.5 env and get a class not found exception with no prior warning when compiling. I found this out the hard way with javax.swing.event.RowSorterEvent/Listener. Both entered "Since 1.6" but are not caught with -source 1.5
If you installed brew, cmd below will be helpful:
brew cask install java
As of Mac OS X v10.6 (Snow Leopard), you can run Java 6 in 32-bit mode on either 32-bit or 64-bit Intel processor equipped Macs.
If you cannot upgrade to Snow Leopard, Soy Latte is a pre-compiled version of Java 6 for Intel 32-bit.
There are various tricky issues with having multiple versions of Java (Apple's own Java 6 and Oracle JDK 7 or even 8) on one's Mac OS X system, and using different versions for different applications. I spent some time writing up my experience of my experience of installing and configuring various versions of JDK on Mac OS X 10.9.2.
In 2022, give a try to sdkman, is better than brew
curl -s "https://get.sdkman.io" | bash
then open a new shell and try list to see what you could install ;-)
sdk list java
At time of writing you could use:
sdk install java 17.0.1-tem
Check this awesome tool sdkman to manage your jdk and other jdk related tools with great ease!
e.g.
$sdk list java
$sdk install java <VERSION>
Since most answers are out of date, here's what works as of end of 2018 under the assumption that
You want to install the GPL version of OpenJDK.[0]
You do not want to install Homebrew
In that case, grab the desired version from one the many available, freely usable OpenJDK editions, e.g.:
AdoptOpenJDK
Amazon Corretto (Great for production, includes backports)
Oracle GPLv2 OpenJDK
Some of these include installers, but if not you can do the following. Assuming here version 11.0.1 for Mac. In your favorite shell, run:
tar -xzf openjdk-11.0.1_osx-x64_bin.tar.gz
sudo mv jdk-11.0.1.jdk /Library/Java/JavaVirtualMachines
# Fix owner and group
sudo chown -R root:wheel /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
# (Optional) Check if the new JDK can be found
/usr/libexec/java_home
=> /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
[0] Note that the Oracle branded JDK has significant licensing restrictions allowing you its use basically only for testing, i.e., not for production. If you do not have a support agreement with Oracle, then it seems risky to me to use their JDK, especially since the differences to OpenJDK are minimal.
Edit: added more choices
I think this other Stack Overflow question could help:
How to get JDK 1.5 on Mac OS X
It basically says that if you need to compile or execute a Java application with an older version of the JDK (for example 1.4 or 1.5), you can do it using the 1.6 because it is backwards compatible. To do it so you will need to add the parameter -source 1.5 and/or -target 1.5 in the javac options or in your IDE.
JDK is the Java Development Kit (used to develop Java software).
JRE is the Java Runtime Environment (used to run any .jar file 'Java software').
The JDK contains a JRE inside it.
On Windows when you update Java, it updates the JRE automatically.
On Mac you do not have a JRE separated you have it, but inside the JDK, so when you update Java it will update your JRE which is inside your JDK;
it doesn't install an JDK for you. You need to get it from somewhere else.
As a rule you cannot install other versions of Java on a Mac than those provided by Apple through Software Update. If you need Java 6 you must have a 64-bit Intel computer. You should always have Java 5 and 1.4 and perhaps 1.3 installed if you have at least OS X 10.4.
If you have VERY much elbow grease and is willing to work with beta software you can install the OpenJDK under OS X, but I don't think you want to go there.