Java 8 For Macos

  пятница 21 февраля
      99

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 Runtime Environment for macOS (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network.

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.

Install HomeBrew first

If you get the error 'already installed', follow the instructions to unlink it, then install again:

upgrade brew:

brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup

Install Java 7 and 8

People on the Stackoverflow cautioned not to install 8 until 7 is installed. So we are going to install JDK 7 first.

Unlike other version managers such as NVM, jEnv itself doesn’t install JDKs. You have to do it yourself. Luckily, Homebrew Cask made this task really easy. But before doing that, let’s check if we already have JDK 7 installed by Homebrew Cask:

install Java 7:

brew cask install java7

If you run into permission issue, add sudo at the beginning of the above command.

As of today, Java 8 is the latest stable. Run the following command to install Java 8:

brew cask install java

These two JDKs will be installed at the following directories. Your JDKs’ minor and patch versions might be different.

Enter jEnv

Now it is time to install jEnv:

brew install jenv

Add the following lines to ~/.bash_profile. This will initialize jEnv.

ps. If you're using Zsh just like me.

jEnv doesn’t install JDKs, so we have to tell jEnv where to look for them. Type these commands to register JDKs in jEnv (replace the minor and patch versions with yours):

before you add to jenv.

Then

After that, run this command to list all registered JDKs:

jenv versions

The version with an asterisk is the active version.

In my case, I need to keep JDK 7 as my default version, so I set the global version to 1.7:

jenv global oracle64-1.7.0.79

Hearts of iron iv field marshal edition. And in my project, I set the local JDK version to 1.8:

The above command will create a .java-version file at project root. Its content is the version I just picked for this project:

oracle64-1.8.0.66