Don't worry, we've got a clear guide to show you how to install it on macOS. Guide you through the process of downloading and installing Java on Mac OS X. If you have not yet installed Apple's Java OS X 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences app. See 'Note for Users of OS X that Include Apple Java 6 Plug-in'. There can be multiple JDKs installed on a system, as many as you wish.
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
but previous versions are at
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?
user3763100user3763100
22 Answers
Don't rely on Oracle to install Java properly on your Mac.
Use Homebrew. this will install the latest jdk:
If you want to manage multiple versions of Java on your Mac, consider using jenv.
UPDATE: Now that Java 8 is no longer the most current version, if you want Java 8 install it this way:
To get a list of all older versions of java:
brew tap caskroom/versions
and then use brew search java
.We use brew cask since we'd otherwise use the Oracle GUI installer that will likely not install Java properly on your Mac. (Use brew cask install APP to install GUI apps; use brew install APP.) Java is not a GUI app; It should not require 'cask' but at least Oracle is consistent.
l3xl3x
For El Capitan, Sierra and High Sierra
First install and update brew from Terminal:
Java 8:
Java Latest:
kavehmbkavehmb
I just did this on my MBP, and had to use
in order to get java8 to install.
Jain WaldripJain Waldrip
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:
- No need to set up any version of Java on your local machine (you'll just run Java within a container which you pull from Docker Hub)
- Very easy to switch to different versions of Java by simply changing the tag on the container.
- Project dependencies are installed within the container - so if you mess up your config you can simply nuke the container and start again.
A very simple example:
Create a
Dockerfile
:- Here we are specifying the Java container running version 8 of the SDK (
java:8
- to use Java 7, you could just specify:java:7
) - We are mapping the local directory with the directory:
/usr/src/myapp
inside the container
Create a
docker-compose.yml
file:Now, assume we have this Java file:
HelloWorld.java
So we have the following file structure:
You can do various Java things like:
compile:
- You should note that the HelloWorld.class shows up in your current directory (this is cause we've mapped the current directory to the location inside the container where our code exists
run:
- Note: the first time you run this it will fetch the image etc. This will take a while - it only happens the first time
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 run- the rest of the line is the command to run inside the container.
This 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:
- I haven't really tried this within an IDE like IntelliJ - so not entirely sure how that aspect of things would work. Though it looks like docker support is coming
- Here is a significantly more complex example running Microservices with Spring Boot, Zuul and Docker
toast38cozatoast38coza
Java8 is no longer available on homebrew,
brew install java8
will not work.Instead, use:
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:For those who don't want to run through the details, here is a summary:
Dave KerrDave Kerr
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.
- You can find an useful guide here,Homebrew Cask Installation Guide.Remember to tap 'caskroom/versions' running in the terminal:
brew tap caskroom/versions
- After that, install jenv with:
brew install jenv
- Install whatever version you want with cask
brew cask install java8
(orjava7
orjava
if you want to install the latest version, jdk9) - The last step is to configure which version to run (and let jenv to manage your JAVA_HOME)
jenv versions
to list all versions installed on your machine and then activate the one you want withjenv 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
Benedetto AbbenantiBenedetto Abbenanti
ArunArun
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:
You can change them by modifying the
/etc/profile
content. Just add (or modify) the following two lines at the end of the file:In my case, it should be like the following if I want to use:
Java 7:
Java 8:
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 8:
The process is similar if your java folder is located in different locations.
nxhoafnxhoaf
Assumption: Mac machine and you already have installed homebrew.
Install cask:
To install latest java:
To install java 8:
If you want to install/manage multiple version then you can use 'jenv':
Install and configure jenv:
Add the installed java to jenv:
To see all the installed java:
Above command will give the list of installed java:
Configure the java version which you want to use:
To set JAVA_HOME:
Lyncean PatelLyncean Patel
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:
You can now set it at startup or call the script afterwards.
Install the JDK for Mac.
Install the JDK for Mac.
Java 7
Java 8
Nathan DunnNathan Dunn
Run these commands on mac High Sierra
and check with command
TLbizTLbiz
You have multiple sources to obtain an easy-to-use installer app to put Java on your Mac. Other answers suggesting Brew or other approaches seem a bit extreme to me. Just download a Mac installer from a trusted source and run it.
Here is a flowchart diagram for finding a source of Java 11, some of which also offer Java 8.
Why 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.
Vendors
For a rather exhaustive list of past and present JVM implementations, see this page at Wikipedia.
Here are three currently-active sources I know of.
Oracle JVM
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.
Zulu & Zing by Azul
Azul Systems provides a variety of JVM products.
- Their
Zulu
line is based directly on OpenJDK, and is available at no cost with optional paid support plans. - Their
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.
AdoptOpenJDK.net
AdoptOpenJDK is a community-led effort to build binaries of the OpenJDK source. They intend to offer updates over time, as donated by community members.
- Your choice of either HotSpot or OpenJ9 engine.
- Builds available for macOS, Linux, and Windows.
OpenJ9 by Eclipse
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:
- Visiting the
/Library/Java/JavaVirtualMachines/
folder to see an item for the new JVM. - Running a console such as Terminal.app and type
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.
Basil BourqueBasil Bourque
SanthoshSanthosh
Best way is to use Brew package manager but the command
fails with error:
So use
How did I find 'caskroom/versions/java8': using brew search command:
Navjot BhardwajNavjot Bhardwaj
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:
stderrstderr
Easiest way -
P.S - What is brew-cask ? Homebrew-Cask extends Homebrew , and solves the hassle of executing an extra command - “To install, drag this icon…” after installing a Application using Homebrew.
sapysapy
Simplest is to download the dmg file from following site and install by double click
look for available JVMs from home directory
and update the .bash_profile with relevent version
and finally
vimal krishnavimal krishna
If you are using it NOT for personal use, you might want to use OpenJDK instead to avoid any potential lawsuit from Oracle.
Edmund LeeEdmund Lee
I would suggest using the SDK man that is quite easy to change the Version ( temporarily and permanent ) and it provides other SDKs as well. I have been using the SDK man for more than a year now.
saif alisaif ali
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.
argarg
Below steps worked for me.
1) Uninstall all jdks
In the Terminal window Copy and Paste the command below:
2) Install APPLE jdk.
3) Download latest JDK from Oracle and install it , for me it was JDK 1.82
Thats all it will work like a charm.
sembiansembian
I also had the same problem. But after little hit and trial, I was able to resolve the issue.
Try removing 1.6 sdk by sudo rm and restart your mac.
Download again the .dmg file. Chances are that the .dmg installer you downloaded, might be corrupt. Install again.
Run following command after installation. It gives path for jdk 8./usr/libexec/java_home -v 1.8
Also you can run and see jdk 8 folder. The files may be hidden.ls -al /Library/Java/JavaVirtualMachines/
Sandeep ShabdSandeep Shabd
protected by RaviFeb 5 '18 at 9:16
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?