If we want to use the Java 8 language features the –source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the – target value should be 1.8. The default value for both of them is 1.6 version. In this tutorial, we installed the Java 8 and Java 11 via Homebrew (Step 1), and Java 14 manually (Step 2), so this Mac has three versions now. And the Mac is using the JDK 14. And the Mac is using the JDK 14. Download Java for OS X directly from Oracle. Get the latest version If an app or webpage you want to use asks you to install Java software, you can download the current version of Java for OS X directly from Oracle's website. Now run $ java -version, you can see the new jdk version is used by output info. $ java -version openjdk version '1.8.0212' OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0212-b03) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode) References.
This article shows you how to install Java on Mac OSX, and also how to do Java/JDK version switching.
Tested with
- Mac OS 10.15.3
- JDK 8, 9, 10, 11, 12, 13 (AdoptOpenJDK)
Note
On Mac OSX, Java should installed in this folder; it is Mac’s standard.
We will show you two ways to install Java JDK on Mac, via the popular Homebrew package manager and manually installation.
1. Homebrew
1.1 Install Homebrew and update it.
1.2 Add adoptopenjdk/openjdk.
1.3 Find all available JDK.
The output may vary.
1.4 Java 8, 9, 10, 11, 12, 13, choose one to install.
This example will install Java 8 and 11 for testing.
1.5 Where Java is installed? /usr/libexec/java_home -V
Homebrew will install the JDK at folder /Library/Java/JavaVirtualMachines/
, and this folder is Mac’s standard folder for Java installs.
1.6 Test it, by default, Mac takes the highest version.
1.7 How to do version switching? Refer to below 3. version switching
2. Manual installation
The example shows you how to download the early access JDK 14 and install it on Mac OSX.
Steps
Java 8 Download Mac Os
- Download JDK.
- Puts the JDK folder at
/Library/Java/JavaVirtualMachines
. - Export
JAVA_HOME
.
2.1 Download the early access JDK 14 from the OpenJDK website.
2.2 Extracts tar file to /Library/Java/JavaVirtualMachines
2.3 Export JAVA_HOME
.
Find out where is JDK 14.
Create or edit the existing ~/.bash_profile
with a text editor.
Export JAVA_HOME
, save and exit.
Download Java Version 8 For Mac Os
Reflect the changes
2.4 Test it.
3. Version Switching
In this tutorial, we installed the Java 8 and Java 11 via Homebrew
(Step 1), and Java 14 manually (Step 2), so this Mac has three versions now. And the Mac is using the JDK 14.
Note
There are tools like jEnv to manage the Java version switching, but I prefer to manage with export JAVA_HOME
manually, it’s simple and easy to understand, no black box magic.
3.1 Create or edit the existing ~/.bash_profile
with a text editor like vim or nano, export JAVA_HOME
to the specified JDK we want to use on Mac.
The above changes will make JAVA_HOME
point to JAVA 8.
3.2 Reflect the changes.
Done.
If we want to switch JDK version again, update the ~/.bash_profile
and export JAVA_HOME
to other JDK version.
References
Java Version 8 Download For Mac
Related Articles
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.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 addjava
to your path. To do this, you must install the JDK.