8 Installation Of The JDK And The JRE On MacOS

Go to main content 8 Installation of the JDK and the JRE on macOS

This topic includes the following sections:

  • System Requirements for Installing the JDK and JRE on macOS

  • Determining the JRE Version Installed on macOS

  • Determining the Default JDK Version on macOS

  • Installing the JDK on macOS

  • Installing the JRE on macOS

  • Uninstalling the JDK on macOS

  • Uninstalling the JRE on macOS

  • Installation FAQ on macOS Platform

  • Notes for Users of macOS That Include the Apple Java 6 Plug-in

System Requirements for Installing the JDK and JRE on macOS

The following are the system requirements for installing the JDK and the JRE on macOS:

  • Any Intel-based computer running macOS.

  • Administrator privileges.

    You cannot install Java for a single user. Installing the JDK and JRE on macOS is performed on a systemwide basis for all users. Administrator privileges are required to install the JDK and JRE on macOS.

  • When you install the JDK, it also installs the JRE. However, the system will not replace the current JRE with a lower version.

    To determine the current JRE version installed on your system, see Determining the JRE Version Installed on macOS. To install an earlier version of the JRE, you must first uninstall the current version. See Uninstalling the JRE on macOS.

  • When you install the JRE, you can install only one JRE on your system at a time. The system will not install a JRE that has an earlier version than the current version.

    To determine the current JRE version installed on your system, see Determining the JRE Version Installed on macOS. To install an earlier version of the JRE, you must first uninstall the current version. See Uninstalling the JRE on macOS.

    Note:

    Installing a JRE from Oracle will not update java -version symlinks or add java to your path. To do this, you must install the JDK.

Determining the JRE Version Installed on macOS

Only one JRE can be installed on the system at any time. Installing a JRE removes the previously installed JRE.

The JRE version installed on the system can be determined in one of two ways:

  • From System Preferences, and then the Other section, click the Java icon. This starts the Java Control Panel. You then click About to display the version information.

  • Enter the following in a Terminal window (note the escaped space character, ignore line break):

    % /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version

Note:

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 application. See Notes for Users of macOS That Include the Apple Java 6 Plug-in.

The system will not install a JRE that has an earlier version than the current version. If you want to install an earlier version, then you must first uninstall the existing version.

Determining the Default JDK Version on macOS

When starting 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 from the default version of the JDK.

There can be multiple JDKs installed on the macOS system.

You can determine which version of the JDK is the default by entering java -version in a Terminal window. If the installed version is 10 Interim 0, Update 2, and Patch 1, then you see a string that includes the text 10.0.2.1. For example:

$ java -version java version "10.0.2.1-ea" Java(TM) SE Runtime Environment (build 10.0.2.1-ea+13) Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)

Note:

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 application. See Notes for Users of macOS That Include the Apple Java 6 Plug-in.

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

$ /usr/libexec/java_home -v 10.0.2.1 --exec javac -version

Installing the JDK on macOS

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

To install the JDK on macOS:
  1. Download the JDK .dmg file, jdk-10.interim.update.patch-macosx-x64.dmg.

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

  2. From either the browser Downloads window or from the file browser, double-click the .dmg file to start it. A Finder window appears that contains an icon of an open box and the name of the .pkg file.
  3. Double-click the JDK 10.pkg icon to start the installation application. The installation application displays the Introduction window.
  4. Click Continue. The Installation Type window appears.
  5. Click Install. A window appears that displays the message: Installer is trying to install new software. Enter your password to allow this.
  6. Enter the Administrator user name and password and click Install Software. The software is installed and a confirmation window is displayed.
After the software is installed, you can delete the .dmg file if you want to save disk space.

Installing the JRE on macOS

To install the JRE on an macOS platform:
  1. Download the JRE .dmg file, jre-10.interim.update.patch_osx-x64_bin.dmg.

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

  2. From either the browser Downloads window or from the file browser, double-click the .dmg file to launch it. A Finder window appears that contains an icon of an open box and the name of the .app file.
  3. Double-click the Java 10.app icon to start the installation application. The installation application displays the Welcome window.
  4. Click Next. The software is installed and a confirmation window is displayed.
  5. Click Close.

Uninstalling the JDK on macOS

To uninstall the JDK on macOS: You must have Administrator privileges.

Note:

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 that you perform an update of the OS.

  1. Go to /Library/Java/JavaVirtualMachines.
  2. Remove the directory whose name matches the following format by executing the rm command as a root user or by using the sudo tool: /Library/Java/JavaVirtualMachines/jdk-interim.update.patch.jdk

    For example, to uninstall 10 Interim 0 Update 2 Patch 1:

    $ rm -rf jdk-10.0.2.1.jdk

Uninstalling the JRE on macOS

To uninstall the JRE on macOS: You must have Administrator privileges to remove one directory and one file (a symlink).

Note:

Do not 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 that you perform an update of the OS.

  1. Go to /Library/Internet Plug-Ins.
  2. Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
  3. Go to /Library/PreferencePanes.
  4. Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.

Installation FAQ on macOS Platform

This topic provides answers for the following frequently asked questions about installing JDK and JRE on macOS computers.

1. Should I install the JRE or the JDK?

If you only plan to run Java applications, then install the Java Runtime Environment (JRE). The JRE is also referred to as Oracle Java. After you have installed the JRE, you can start Java applets and applications by double-clicking JAR files, JNLP files, and by using the browser. Note that 32-bit browsers, such as Firefox in 32-bit mode, and Chrome, are not supported by the JRE.

If you also plan to create Java applications, then install the Java Development Kit (JDK).

2. How do I find out which version of Java is the system default?

When you start a Java application by clicking a JNLP file, or through the browser, it uses the installed JRE. Only one JRE can be installed. See Determining the JRE Version Installed on macOS.

When you run a Java application from the command line, it uses the default JDK. If you do not develop Java applications, then you do not need to worry about this. See Determining the Default JDK Version on macOS.

Note:

If you have not yet installed Apple's Java macOS 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences application. See Notes for Users of macOS That Include the Apple Java 6 Plug-in.

3. How do I clear the Java cache?

Follow these steps:

  1. From System Preferences, start the Java Control Panel from Other section by clicking the Java icon.

  2. From the Java Control Panel, on the General tab, go to Temporary Internet Files section and click Settings .

  3. In the Temporary Files Settings window, click Delete File.

  4. From the Delete Files and Applications dialog box, select Cached Applications and Applets and click OK to clear those files from the cache.

To clear the applet and Web Start cache from a window, use the following command (note escaped space character):

$ rm -rf ~/Library/Application\ Support/Oracle/Java/Deployment/cache

4. How are Java updates managed on macOS?

Every time you start a Java applet or a Java Web Start (JWS) application, the system starts your program and determines in the background (so that performance of your Java application is not affected) if it has checked for a Java update in the last 7 days.

If an update is available, then the Software Update window appears.

Select Next, and enter your user Name and Password.

The latest update gets downloaded and installed. Restart the browser and other applications to work on the new Java update.

5. How do I uninstall Java?

Depending on your installation, see the related link:

  • Uninstalling the JDK on macOS

  • Uninstalling the JRE on macOS

6. I have installed Java for macOS 2012-006 and Apple Java 6 can no longer be used for applets or Web Start. How do I get it back?

The Java for macOS 2012-006 update from Apple uninstalls the Apple-provided Java applet plug-in from all web browsers. You can download the latest version of Java from Java SE Downloads, which has improved security, reliability, and compatibility.

If you prefer to continue using Apple's Java 6 plug-in, follow the steps provided in the Java for OS X 2014-001 topic at the Apple Developer site.

7. After installing Java for macOS 2012-006, can I continue to use Apple's Java 6 alongside the macOS JDK or JRE for Java 10?

If you want to continue to develop with Java 6 using command-line, then you can modify the startup script for your favorite command environment. For bash, use this:

$ export JAVA_HOME=`/usr/libexec/java_home -v 1.6`

Some applications use /usr/bin/java to call Java. After installing Java for macOS 2012-006, /usr/bin/java will find the newest JDK installed, and will use that for all of the Java-related command-line tools in /usr/bin. You may need to modify those applications to find Java 6, or contact the developer for a newer version of the application.

8. Can I restore Apple Java after uninstalling Oracle Java?

Go back to Apple Java using the following instructions:

  1. Uninstall Oracle Java by deleting the plug-in file. From a command-line, enter:

    % sudo rm -rf “/Library/Internet Plug-Ins/JavaAppletPlugin.plugin”

  2. Create a symlink using the following command, entered on a single line:

    % sudo ln -s /System/Library/Java/Support/CoreDeploy.bundle/Contents/JavaAppletPlugin.plugin ”/Library/Internet Plug-Ins/JavaAppletPlugin.plugin”

9. I am running Mountain Lion (macOS 10.8) or later and Gatekeeper is blocking an app from launching. What is going on?

Gatekeeper, introduced in Mountain Lion (macOS 10.8), is designed to prevent potentially malicious application packages (apps) from starting. When you attempt to start an app that does not meet certain criteria, Gatekeeper will block it. To override this, you can modify the Gatekeeper's default settings to App Store and identified developers from Settings, General, and Allow apps downloads from section.

To create a Java application that will start without interruption under the default Gatekeeper settings, the app must be bundled with a JRE, use Oracle's launcher stub, and be signed with an Apple Developer ID. For details on creating an app that satisfies these requirements, see Self-Contained Application Packaging for OS X in the Java Platform, Standard Edition Deployment Guide.

10. What happened to the Java Preferences app in Application Utilities?

The Java Preferences app was part of the Apple Java installation and is not used by Oracle Java. Therefore, macOS releases from Apple that do not include Apple Java will not include Java Preferences.

One of the functions of Java Preferences was to set the current version of the JRE. Under Oracle Java, only a single version of the JRE can be installed at a time. See Installing the JRE on macOS.

To access the Java Control Panel, in the System Preferences panel, click the Java icon. If you don’t see the Java icon in the System Preferences, in the Other section, then you do not have an Oracle JRE installed.

11. I have Oracle's version of the JRE installed, but it is not listed in Java Preferences.

This is correct. The JRE will not show up in the Java Preferences list unless you install the full JDK.

12. I have Oracle's version of the JRE installed, but when I try to run the java command from the command line, it does not work.

Installing a JRE from Oracle does not update java -version symlinks or add the java command to your path. For this functionality, you must install the full JDK.

Notes for Users of macOS That Include the Apple Java 6 Plug-in

If you have not yet installed Apple's Java macOS 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences application.

There is an important difference about the installation of Oracle Java (both JRE and JDK) that you should be aware of. The Java Preferences application, started by selecting Applications and then Utilities, is part of Apple's implementation of Java. After Apple no longer distributes Java as part of their release, the Java Preferences application is retired.

Under Apple's implementation of Java, it was possible to have multiple JREs installed. The Java Preferences application was used to determine the first compatible version that would be used. You can change the default JRE by starting Java Preferences and then dragging Java SE 10 to the top of the list.

Note:

  • The Java Preferences window contains a list of installed JREs. Java applications and command-line tools use the listed order to determine the first compatible version to use. The Vendor column indicates whether the Java release is supplied by Apple or Oracle. The Version column specifies the version of Java that is installed.

  • Reordering the list, by dragging Java SE 10 to the top, makes it the default version of Java.

  • If you install only Oracle Java JRE 10, then it will not appear in this list. You must install the full JDK for JRE 10 to be listed.

Từ khóa » Cách Cài Jdk 1.8