Jdk For Mac Os X

This page describes how to install and uninstall JDK 8 for OS X computers.

This page has these topics:

See 'JDK 8 and JRE 8 Installation Start Here' for general information about installing JDK 8 and JRE 8.

OpenJDK is a production-ready open-source build of the Java Development Kit, version 12.0.2, an implementation of the Java SE 12.0.2 Platform under the GNU General Public License, version 2, with the Classpath Exception. Commercial builds of JDK 12.0.2 from Oracle under a non-open-source license, for a wider range of platforms, can be found at the Oracle Technology Network.

  • 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.
  • Java SE Development Kit 8 Downloads. Thank you for downloading this release of the Java™ Platform, Standard Edition Development Kit (JDK™). The JDK is a development environment for building applications, applets, and components using the Java programming language.
  • Mac OS X 및 Apple Java 6 지원 중단. Apple은 Mac OS X 10.11(El Capitan)이 Java 6을 지원하는 마지막 OS X 릴리스라는 공지를 게시했으므로 Java 6에 종속되는 응용 프로그램을 사용하는 개발자는 앱을 Oracle에서 제공하는 최신 Java 버전으로 이전하는 것이 좋습니다.

See 'OS X Platform Install FAQ' for general information about installing JDK 8 on OS X.

System Requirements

Observe the following requirements:

  • Any Intel-based computer running OS X 10.8 (Mountain Lion) or later.

  • Administrator privileges.

Note that installing the JDK on OS X is performed on a system wide basis, for all users, and administrator privileges are required. You cannot install Java for a single user.

Installing the JDK also installs the JRE. The one exception is that the system will not replace the current JRE with a lower version. To install a lower version of the JRE, first uninstall the current version as described in 'Uninstalling the JRE'.

JDK Installation Instructions

When you install the Java Development Kit (JDK), the associated Java Runtime Environment (JRE) is installed at the same time. The JavaFX SDK and Runtime are also installed and integrated into the standard JDK directory structure.

Depending on your processor, the downloaded file has one of the following names:

  • jdk-8uversion-macosx-amd64.dmg

  • jdk-8uversion-macosx-x64.dmg

Where version is 6 or later.

  1. Download the file.

    Before the file can be downloaded, you must accept the license agreement.

  2. From either the Downloads window of the browser, or from the file browser, double click the .dmg file to launch it.

    A Finder window appears containing an icon of an open box and the name of the .pkg file.

  3. Double click the package icon to launch the Install app.

    The Install app displays the Introduction window.


    Note:

    In some cases, a Destination Select window appears. This is a bug, as there is only one option available. If you see this window, select Install for all users of this computer to enable the Continue button.

  4. Click Continue.

    The Installation Type window appears.

  5. Click Install.

    A window appears that says 'Installer is trying to install new software. Type your password to allow this.'

  6. Enter the Administrator login and password and click Install Software.

    The software is installed and a confirmation window appears.

  7. Refer to http://www.oracle.com/technetwork/java/javase/downloads/jdk-for-mac-readme-1564562.html for more information about the installation.

  8. After the software is installed, delete the .dmg file if you want to save disk space.

Determining the Default Version of the JDK

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.

When launching a Java application through the command line, the system uses the default JDK. It is possible for the version of the JRE to be different than the version of the JDK.

You can determine which version of the JDK is the default by typing java -version in a Terminal window. If the installed version is 8u6, you will see a string that includes the text 1.8.0_06. For example:

To run a different version of Java, either specify the full path, or use the java_home tool:

For more information, see the java_home(1) man page.

Uninstalling the JDK

To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.

For example, to uninstall 8u6:

Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.

In this article, see how to manage multiple JDKs on Mac OS, Linux and Windows WSL2.

Join the DZone community and get the full member experience.

Join For Free

If you, like me, have to deal with multiple projects at different stages, like one being legacy, another one being the latest, and another one being a library or tool consumed by users also using different versions of Java, then you have a small Multiple JDK problem, assuming you only care for one vendor of JDK; otherwise, you have a Matrix JDK problem.

Installing, managing, and switching between JDKs in your computer is no easy task these days where the majority of developers are still on Java 8, while a good chunk is now moving to Java 11. And there are many ways to do that.

This article is to help you through that process.

The Manual Way

You can go after your JDK vendor-of-choice website and download binaries, and install them all manually (or even better just extract them to some folder like $user/jdks and be done with it. But then you have to always verify and update JAVA_HOME to point to the one you really want for this and for that project.

Solutions for this would include using bash scripts, bash functions, and so on. The main problem? You may simply forget to call the script/function, and be hit with some UnsupportedClassVersionError to then only realize what's wrong.

I'll leave this to you to dig the internet for solutions, if you prefer the manual way. For advanced users, it may be the best choice. But I prefer some tooling for this. So, let's dive in:

The Better Way

In my opinion, the ideal way is by combining two open source tools that exist already for quite some time and you may already know at least one of them. What you don't know is that you can combine them.

Let's see how we get them to play ball together…

Install Multiple JDKs

Once you have SDKMAN! installed and configured, you will type:





Once you find the vendor and version you want to install, you will type:

'>




Let’s add four JDKs, two recent versions of Oracle OpenJDK and two LTS versions by AdoptOpenJDK.

Whenever asked by SDKMAN!, do not set any of them as the default.

  1. AdoptOpenJDK build of OpenJDK 8u252 — LTS
  2. AdoptOpenJDK build of OpenJDK 11.0.7 — LTS
  3. Oracle OpenJDK 14 — Latest GA
  4. Oracle OpenJDK 15 — Early Access Builds of next release

These four versions should cover you well for legacy projects still stick to Java 8, but also put you in a nice place for modern projects with Java 11 as well as the possibility to experiment new features and enhancements on Java 14 and Java 15.

Alright, you’ve got 4 JDKs installed locally with SDKMAN! —I think this tool is really great for this use case, and I hope you enjoyed it too.

All JDKs installed can be found inside the following directory:





Now, if you do want to just use one JDK at all times and not have to switch back and forth, you can use SDKMAN! to set your JDK of choice:





You can stop here and just use SDKMAN! but you will eventually forget to switch back based on the project you are working on, just like by using some manual shell script. And because of this, I prefer to auto-switch.

Manage Multiple JDKs With jEnv

While SDKMAN! can install and manage JDKs, the tool doesn't do a great job at auto-switching between versions for you automatically as you move from project A to project B.

For that, you will want jEnv.

Once you have it installed and configured, and multiple JDKs, whether with SDKMAN! or some other way, you will need to add those JDKs to jEnv. Here’s how:





Repeat the command jenv add for all other 3 versions.

jEnv has excellent features especially for those constantly using terminals. It will allow you to:

  1. Set a Java version for your overall system.
  2. Set a Java version for the current directory/project you are in.
  3. Set a Java version for the current shell.

jEnv uses shim binaries and also manipulates the JAVA_HOME environment variable for you automatically. So, once you have these settings, jEnv will switch to whatever version makes most sense, based on the priority above and based on where you are. Neat! It has other nice features, so check the website for more documentation.

Auto-Switch Between Multiple JDKs

Jdk

Now you have Java 8, 11, 14 and 15-EA available. So how do you switch back and forth? Let's set versions and switch back and forth.

First you set a Java version to be global default. I like to use an Early Access as my system default. Whenever I hit a new project, I will automatically attempt to work with an upcoming release, and this could help me identify potential problems I can then report back to the OpenJDK project. But you do you…





With this setting, whenever you hit any folder on your terminal and you type java -version you will get OpenJDK 15 EA.

If you do have a project that must use Java 8, then you navigate to that project folder, and you type:





This will create a file called .java-version with the following content:





Jdk For Mac Os X

This file is what tells jEnv which JDK to use for when the terminal is on this folder.

Finally, if you are on some location and you want to temporarily switch to a specific JDK version, then you use jenv shell.

Jdk 7 For Mac Os X

Here's a demonstration that can explain better all these concepts and how the Auto-Switch works.

I hope you enjoyed the read, and if you have questions, just reach out to me on Twitter.

Download Jdk For Mac

java,tutorial,jdk,multiple jdks,sdkman,jenv

Published at DZone with permission of Bruno Borges. See the original article here.

Install Jdk For Mac

Opinions expressed by DZone contributors are their own.