I want to do some programming with the latest JavaFX, which requires Java 8. I'm using IntelliJ 13 CE and Mac OS X 9 Mavericks. I ran Oracle's Java 8 installer, and the files look like they ended up at
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk
but previous versions are at
/System/Library/Java/JavaFrameworks/jdk1.6....
Not sure why the latest installer puts this in /Library
instead of /System/Library
(nor what the difference is). But /usr/libexec/java_home
doesn't find 1.8, so all the posts I've found on how to set your current java version don't work. I've tried adding a symbolic link to make it look like 1.8 is in the /System/Library...
path, but it doesn't help. /usr/libexec/java_home -V
still only lists the old Java 1.6.
Ironically, the "Java" control panel under System Preferences shows only Java 1.8!
Why doesn't Oracle's installer put it where it really goes? And how can I work around this problem?
This question is related to
java
macos
java-8
installation
Assumption: Mac machine and you already have installed homebrew.
Install cask (with Homebrew 0.9.5 or higher, cask is included so skip this step):
$ brew tap caskroom/cask
$ brew tap caskroom/versions
To install latest java:
$ brew cask install java
To install java 8:
$ brew cask install adoptopenjdk/openjdk/adoptopenjdk8
If you want to install/manage multiple version then you can use 'jenv':
Install and configure jenv:
$ brew install jenv
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
Add the installed java to jenv:
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.11.0_2.jdk/Contents/Home
To see all the installed java:
$ jenv versions
Above command will give the list of installed java:
* system (set by /Users/lyncean/.jenv/version)
1.8
1.8.0.202-ea
oracle64-1.8.0.202-ea
Configure the java version which you want to use:
$ jenv global oracle64-1.6.0.39
To set JAVA_HOME:
$ jenv enable-plugin export
If you are using it NOT for personal use, you might want to use OpenJDK instead to avoid any potential lawsuit from Oracle.
brew cask install adoptopenjdk8
I'm having the same problem to solve, because I need to install JDK8 to run Android SDK Manager (because it seems that don't work well with JDK9). However, I tell you how I solve all problems on a Mac (Sierra).
First, you need brew with cask and jenv.
brew tap caskroom/versions
brew install jenv
brew cask install java8
(or java7
or java
if you want to install the latest version, jdk9)jenv versions
to list all versions installed on your machine and then activate the one you want with jenv global [JDK_NAME_OF_LIST]
You could find other useful informations here on this Github Gist brew-java-and-jenv.md, on this blog Install multiple JDK on a Mac and on Jenv Website
brew cask commands were disabled on 2020-12-21 with the release of Homebrew 2.7.0.
Use the below commands to install JDK
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
Run these commands on mac High Sierra
brew update
brew tap caskroom/versions
brew cask install java8
and check with command
java -version
Using brew
brew install Caskroom/cask/java
Below steps worked for me.
1) Uninstall all jdks
In the Terminal window Copy and Paste the command below:
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefpane
2) Install APPLE jdk.
https://support.apple.com/kb/DL1572?locale=en_US
3) Download latest JDK from Oracle and install it , for me it was JDK 1.82
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
Thats all it will work like a charm.
Install with Homebrew
The version of Java available in Homebrew Cask previous to October 3, 2018 was indeed the Oracle JVM. Now however, it has now been updated to OpenJDK. Be sure to update Homebrew and then you will see the lastest version available for install.
1. install Homebrew if you haven't already. Make sure it is updated:
brew update
2. Add the casks tap, if you haven't already (or you are not seeing older Java versions anymore with step #3):
brew tap homebrew/cask-versions
3. and for the AdoptOpenJDK versions, add that tap:
brew tap adoptopenjdk/openjdk
These casks change their Java versions often, and there might be other taps out there with additional Java versions.
4. Look for installable versions:
brew search java
or for AdoptOpenJDK versions:
brew search jdk
5. Check the details on the version that will be installed:
brew cask info java
or for the AdoptOpenJDK version:
brew cask info adoptopenjdk
6. Install a specific version of the JDK such as java11, adoptopenjdk8, or just java or adoptopenjdk for the current. For example:
**brew cask install java**
**brew cask install java8**
**brew cask install java11**
You can use the fully qualified path to older versions as well:
brew cask install homebrew/cask-versions/java11
It seems that nobody has mentioned SDK man (https://sdkman.io/) yet.
SKD man allows installing multiple versions of Java on Mac and easy switching between these versions. More information is available at https://sdkman.io/usage.
For example:
$ sdk list java
================================================================================
Available Java Versions
================================================================================
* 12.ea.20-open
11.0.1-zulu
> * 11.0.1-open
10.0.2-zulu
10.0.2-open
9.0.7-zulu
9.0.4-open
8.0.192-zulu
8.0.191-oracle
+ 8.0.181-oracle
7.0.181-zulu
1.0.0-rc-10-grl
1.0.0-rc-9-grl
1.0.0-rc-8-grl
================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
$ sdk install java 8.0.191-oracle
$ sdk use java 8.0.191-oracle
Using java version 8.0.191-oracle in this shell.
$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
$ sdk use java 11.0.1-open
Using java version 11.0.1-open in this shell.
$ java -version openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
```
I have applications that use both Java 7 and 8 and have to go back and forth all the time.
I use this script written by Johan:
http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/
You can now set it at startup or call the script afterwards.
Install the JDK for Mac.
Java 7
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Java 8
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Updated recommendation!!:
Use jenv https://www.jenv.be/ and homebrew.
Then its just jenv global oracle6401.6.0.39
and its set.
Easiest way
1) brew cask install java
2) java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
P.S - Cask is an extension to Homebrew that is intended to manage large Mac binaries and graphical applications, but using the Homebrew interface. Also see this answer on Apple StackExchange.
For latest version of Intellij IDEA users there is an option to download JDK directly from the IDE: https://www.jetbrains.com/help/idea/sdk.html#jdk-from-ide
If you have several Java versions on your machine and you want to choose it dynamically at runtime, i.e, in my case, I have two versions:
ls -la /Library/Java/JavaVirtualMachines
drwxr-xr-x 3 root wheel 96B Nov 16 2014 jdk1.7.0_71.jdk/
drwxr-xr-x 3 root wheel 96B Mar 1 2015 jdk1.8.0_31.jdk/
You can change them by modifying the /etc/profile
content. Just add (or modify) the following two lines at the end of the file:
export JAVA_HOME=YOUR_JAVA_PATH/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
In my case, it should be like the following if I want to use:
Java 7:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
Java 8:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
After saving the file, please run source /etc/profile
and it should work. Here are results when I use the first and second option accordingly:
Java 7:
java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java 8:
java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
The process is similar if your java folder is located in different locations.
Try :
brew cask install java 8
it will give the below result
8tracksradiohelper adoptopenjdk8 amitv87-pip
corretto8 icons8 vmware-fusion8
x48 zulu8
Next enter:
brew cask install adoptopenjdk8
---- java 8 will be installed in Mac.
Note: Oracle Java 8/9/10 is no longer available for public download (license change).
First install and update brew from Terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap homebrew/cask-versions
brew update
NEW as of June 2019
To install the JDKs from AdoptOpenJDK:
brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
brew cask install adoptopenjdk9
brew cask install adoptopenjdk10
brew cask install adoptopenjdk11
OLD
Java 8:
brew cask install java8
Java Latest:
brew cask install java
Best way is to use Brew package manager but the command
brew cask install java8
fails with error:
Error: No available formula with the name "java8"
So use
brew cask install caskroom/versions/java8
How did I find "caskroom/versions/java8": using brew search command:
brew cask search java8
Oracle has a poor record for making it easy to install and configure Java, but using Homebrew, the latest OpenJDK (Java 14) can be installed with:
brew install --cask adoptopenjdk8
For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step.
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8
Existing users of Homebrew may encounter Error: Cask adoptopenjdk8 exists in multiple taps
due to prior workarounds with different instructions. This can be solved by fully specifying the location with brew cask install adoptopenjdk/openjdk/adoptopenjdk8
.
Please, run the following commands and it will install Java 8 on OS X:
brew tap adoptopenjdk/openjdk
brew install --cask homebrew/cask-versions/adoptopenjdk8
Java8 is no longer available on homebrew, brew install java8
will not work.
Instead, use:
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
See this commit for technical details.
Please note as well you may see issues around Cask adoptopenjdk8 exists in multiple taps
. This is a known issue, currently being worked on, which you can see here:
https://github.com/AdoptOpenJDK/homebrew-openjdk/issues/106
For those who don't want to run through the details, here is a summary:
# To install JDK8
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
# To be able to safely run 'brew cleanup'
brew untap adoptopenjdk/openjdk
brew untap caskroom/versions
brew cleanup
brew cask install caskroom/versions/java8
/Library/Java/JavaVirtualMachines/
is the correct location for the JVM to be installed. This has been the case for several years now. Many years ago, other locations were used, but no longer.
You have a choice of several vendors to obtain an installer app to install a Java implementation on your Mac. Download an installer to run locally and then discard, as you commonly do for many apps.
Your Question mentions JavaFX/OpenJFX. You might find it convenient to use a Java implementation that comes bundled with the OpenJFX libraries, such as LibericaFX from BellSoft or ZuluFX from Azul Systems.
Other answers suggesting the Homebrew package manager seem a bit extreme to me. I am sure Homebrew has some good uses. But to simply run Java, or do Java programming, installing Homebrew is a needless extra step. Installing Homebrew (package manager) for the single goal of obtaining Java is like building a landing strip to park your car instead of using your driveway. If you already have it, fine, use it. But suggesting Homebrew to those who simply need Java is poor advice.
People not already using Home-brew can simply download a Mac installer from a trusted source.
You have multiple sources to obtain an easy-to-use installer app to put Java on your Mac. Run the installer on your Mac just as you do for many other apps.
Here is a flowchart diagram for finding a source of Java 11, some of which also offer Java 8.
Download an installer from a vendor such as Adoptium(AdoptOpenJDK.net).
Run the installer.
JavaVirtualMachines
folder is now correctWhy doesn't Oracle's installer put it where it really goes? And how can I work around this problem?
Not a problem.
The folder /Library/Java/JavaVirtualMachines/
is the new home for JVMs on macOS.
To install a JVM, use an installer, discussed below.
To uninstall, simply use the Finder to delete a JVM from that folder. You will be prompted for system admin password to complete the removal.
Back in 2010, Apple joined the OpenJDK project, along with Oracle, IBM, Red Hat, Azul, and other Java vendors. Each member contributes source code, testing, and feedback to the unified OpenJDK codebase.
Apple contributed most of its Mac-specific code for its JVM. Now Apple no longer releases its own Mac-specific JVM. You now have your choice of JVM supplier, with builds coming from the OpenJDK codebase.
You will find source code at: http://openjdk.java.net
Be aware that in 2017, Oracle, the JCP, and OpenJDK have adopted a new rapid “release train” plan for regularly-scheduled versions of Java to be delivered in a predictable manner.
Read this 2018-07 Azul Systems blog post for many details, Eliminating Java Update Confusion by Simon Ritter.
Also read Java Is Still Free.
For a rather exhaustive list of past and present JVM implementations, see this page at Wikipedia.
Here is a discussion of a few vendors. See the flowchart above for more vendors
Oracle provides JDK and JRE installers for multiple platforms including macOS.
Over the years since acquiring Sun, Oracle has combined the best parts of the two JVM engines, HotSpot and JRocket, and merged them into the OpenJDK project used as the basis for their own branded implementations of Java.
Their new business plan, as of 2018, is to provide a Oracle-branded implementation of Java for a fee in production, and at no cost for use in development/testing/demo. Support for previous releases requires a paid support program. They have declared their intention for their branded release to be at feature-parity with the OpenJDK release. They have even donated their commercial add-ons such as Flight Recorder to the OpenJDK project.
Oracle also releases a build of OpenJDK with no support: http://jdk.java.net/
Oracle has produced a special purpose JDK, GraalVM.
Azul Systems provides a variety of JVM products.
Zulu
line is based directly on OpenJDK, and is available at no cost with optional paid support plans.Zing
line offers commercial JVM products enhanced with alternate technical implementations such as a specialized garbage-collector.Both of their lines offer installers for macOS.
I am currently use Zulu for Java 10.0.1 on macOS High Sierra with IntelliJ 2018.2 and Vaadin 8. I downloaded from this page. By the way, I do not find any Java-related items installed on the Apple System Preferences app.
Adoptium, formerly known as AdoptOpenJDK, is a community-led effort to build binaries of the OpenJDK source. Many of the other vendors of Java implementations support this work at Adoptium.
The OpenJ9 project is an another implementation of the JVM engine, an alternative to HotSpot.
Now sponsored at the Eclipse Foundation, with technology and backing donated by IBM in 2017.
For prebuilt binaries, they refer you to the AdoptOpenJDK project mentioned above.
The installers provided by Oracle or by Azul are both utterly simple to operate. Just run the installer app on your Mac. A window appears to indicate the progress of the installation.
When completed, verify your JVM installation by:
/Library/Java/JavaVirtualMachines/
folder to see an item for the new JVM.java -version
to see the brand and version number of your JVM.After verifying success, dismount the .dmg image in the Finder. Then trash the .dmg file you downloaded.
I just did this on my MBP, and had to use
$ brew tap homebrew/cask-versions
$ brew cask install java8
in order to get java8 to install.
brew
brew install jenv openjdk@8
jenv add /usr/local/opt/openjdk@8
And then add into Intellij IDEA a new SDK with the following path:
~/.jenv/versions/8/libexec/openjdk.jdk/Contents/Home/
I will also suggest to add in your .zshrc
(or .bashrc
)
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
As of May 3, 2020, this site has a download link for jre8u251: https://java.com/en/download/mac_download.jsp
An option that I am starting to really like for running applications on my local computer is to use Docker. You can simply run your application within the official JDK container - meaning that you don't have to worry about getting everything set up on your local machine (or worry about running multiple different versions of the JDK for different apps etc)
Although this might not help you with your current installation issues, it is a solution which means you can side-step the minefield of issues related with trying to get Java running correctly on your dev machine!
The benefits are:
A very simple example:
Create a Dockerfile
:
FROM java:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
java:8
- to use Java 7, you could just specify: java:7
) /usr/src/myapp
inside the containerCreate a docker-compose.yml
file:
version: "2"
services:
java:
build: .
volumes:
- .:/usr/src/myapp
Now, assume we have this Java file:
HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
So we have the following file structure:
.
|_ Dockerfile
|_ docker-compose.yml
|_ HelloWorld.java
You can do various Java things like:
compile:
docker-compose run --rm java javac HelloWorld.java
run:
docker-compose run --rm java java HelloWorld
docker-compose run
- runs a command from within the container-rm
tells docker to remove the container once the command is finished runningjava
is the name of the service/container (from our docker-compose file) against which this command will runThis is quite a cool way of dealing with running different versions of Java for different apps without making a complete mess of your local setup :).
Here is a slightly more complex example which has Maven and a simple Spring app
Disclaimer:
You can try this:
$ brew search jdk
$ brew cask install homebrew/cask-versions/adoptopenjdk8
$ /usr/libexec/java_home
If you are on a Mac, then Homebrew is the way to install stuff.
It seems that version 8 is no longer the most recent, so it isnt available using the default brew cask install java
.
Instead I managed by doing the following:
brew install homebrew/cask-versions/
If this fails, just try the next one directly:
brew install homebrew/cask-versions/adoptopenjdk8
Test with brew cask list
or java -version
for 2021 this one worked for me
brew tap homebrew/cask-versions
brew install --cask adoptopenjdk8
Simplest is to download the dmg file from following site and install by double click
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
look for available JVMs from home directory
ls -al /Library/Java/JavaVirtualMachines
and update the .bash_profile with relevent version
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_XXX.jdk./Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
and finally
source ~/.bash_profile
Source: Stackoverflow.com