Using HomeBrew to Install Java JDK11 on MacOS (2021)
I know there is a post with the exact same title but since it’s a little bit outdated I’d like to post a slightly adjusted version for the people who is googling a updated solution.
Step 1: Install Homebrew (if you haven’t done it already)
$ /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
Step 2: Update it (if you haven’t done it already)
$ brew update
Step 3: Install Java11
$ brew install java11
Step 4: Symlink it
If you skip this step the system won’t be able to find a java runtime for you to use.
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
Step 5: Test
If you see something similar after typing the command with the version flag you’re good to go!
$ java --version
openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9)
OpenJDK 64-Bit Server VM (build 11.0.10+9, mixed mode)
Please let me know if you got issues so I can update this guide. Have a nice day!
SMILE GUIDE: INSTALLING JAVA
By the end of this guide, you’ll be able to understand the process of installing Java on a Mac.
Background
While installing Smile CDR, you may encounter a Java runtime error that can be resolved by installing a JRE (Java Runtime Environment) or JDK (Java Developer Kit). Smile CDR will run against a simple JRE (the JDK is not required to use Smile CDR), but the JDK does come with many tools which can be useful for troubleshooting issues (e.g. jstack, jmap, etc.). The JDK versions supported by Smile CDR are Java 16 and Java 11. Although Java 16 is a newer release, Java 11 is the only long-term supported version and is the JDK we suggest you install. This step-by-step guide will explain how to install a JDK, so that your computer can run Java applications such as Smile CDR.
Objectives
The intent of this document is to provide a step-by-step guide to downloading Java on your Mac. One should be able to successfully complete the installation with little to no technical background.
Prerequisites
There are no prerequisites required.
Installing Java — MacOS, Intel x86 processor (Mac 2019 Model or Older)
Installing Java — MacOS, ARM 64 (Mac 2020 Model or Newer)
Important Note on Rosetta 2
As of November 2020, all Apple laptops are manufactured with an Arm-based Silicone M1 chip. The only version of Java that is compatible with this chip is Java 17, however, Smile does not currently support this version. To rectify the problem, we must also install Rosetta 2, then JDK version 11, which Smile does support. Rosetta 2 is a tool that allows us to run older, non-native Intel x86 apps on the new Mac M1 chips.
There are generally two approaches to installing Rosetta 2
The first approach is done prior to installing a JDK and involves opening your terminal application and entering the following command:
softwareupdate —install-rosetta
This will launch the rosetta installer and you’ll have to agree to a license agreement. Once this is done, you may install Java 11 by following the Installation Instructions below.
The second approach occurs midway through the JDK installation process. If you follow the Installation Instructions below, you will be automatically prompted to install Rosetta (assuming you haven’t already installed Rosetta via the first approach). When this occurs, simply follow the instructions that appear on screen to install Rosetta, then you may proceed with the JDK installation.
Installation Instructions
- Let’s download Java 11, which is a JDK supported by Smile CDR.
Open the followinghttps://www.oracle.com/ca-en/java/technologies/javase-downloads.html
Как установить java 11 на mac os
This topic includes the following sections:
- System Requirements for Installing the JDK on macOS
- Determining the Default JDK Version on macOS
- Installing the JDK on macOS
- Uninstalling the JDK on macOS
- Installation FAQ on macOS Platform
System Requirements for Installing the JDK on macOS
The following are the system requirements for installing the JDK on macOS:
- Any Intel-based computer running macOS.
- Administrator privileges. You cannot install Java for a single user. Installing the JDK on macOS is performed on a systemwide basis for all users. Administrator privileges are required to install the JDK on macOS.
Determining the Default JDK Version on macOS
When starting a Java application through the command line, the system uses the default 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 11 Interim 0, Update 0, and Patch 0, then you see a string that includes the text 11 . For example:
$ java -version java version "11" Java(TM) SE Runtime Environment (build 11) Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
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 11 —exec javac -version
Installing the JDK on macOS
To install the JDK on macOS:
- Download the required JDK .dmg or file from .tar.gz page:
- macOS x64 systems: jdk- 11 . interim.update.patch _macos-x64_bin.dmg OR jdk- 11 . interim.update.patch _macos-x64_bin.tar.gz
- macOS aarch64 (64-bit ARM) systems: jdk- 11 . interim.update.patch _macos-aarch64_bin.dmg OR jdk- 11 . interim.update.patch _macos-aarch64_bin.tar.gz
Click Accept License Agreement .
A Finder window appears that contains an icon of an open box and the name of the .pkg file.
The installation application displays the Introduction window.
The Installation Type window appears.
A window appears that displays the message: Installer is trying to install new software. Enter your password to allow this.
The software is installed and a confirmation window is displayed.
After the software is installed, you can delete the .dmg or .tar.gz file if you want to save disk space.
Uninstalling the JDK on macOS
To uninstall the JDK on macOS:
You must have Administrator privileges.
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.
- Go to /Library/Java/JavaVirtualMachines .
- 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- 11 . interim.update.patch .jdk For example, to uninstall 11 Interim 0 Update 0 Patch 0: $ rm -rf jdk- 11 .jdk
Installation FAQ on macOS Platform
This topic provides answers for the following frequently asked questions about installing JDK on macOS computers.
1. How do I find out which version of Java is the system default?
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.
2. How do I uninstall Java?
3. After installing Java for macOS 2012-006, can I continue to use Apple’s Java 6 alongside the macOS JDK for Java 11 ?
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 11`
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.
4. Can I restore Apple Java after uninstalling Oracle Java?
Go back to Apple Java using the following instructions:
- Uninstall Oracle Java by deleting the plug-in file. From a command-line, enter: $ sudo rm -rf «/Library/Internet Plug-Ins/JavaAppletPlugin.plugin»
- 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»
5. 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.
How To Install Java 11 On Mac
It provides all the steps required to install Java 11 on Mac systems including macOS Sierra, High Sierra, Mojave, and Catalina. Java 11 is an LTS release and it will be supported by Oracle at least till Aug 2024.
April 22, 2020
In this tutorial, we will discuss how to install Oracle Java 11 on Mac systems. This tutorial provides all the steps required to install the LTS version of Java i.e. Oracle Java 11 officially distributed by Oracle for Mac. It provides the steps required to install Java 11 on macOS Catalina. The steps should be the same for other versions of macOS including Sierra, High Sierra, and Mojave.
System Checks
In this step, we will test whether Java is already installed or not. To do so, open the terminal and type java -version as shown in Fig 1. It shows that Java is not installed on my system and also opens a dialog to get more info.
Now press the OK Button to hide the dialog. It might show the existing version of Java if it is already installed on your system as shown in Fig 2.
Download Java 11
Open the download link to select the available versions as shown in Fig 3. Also, go through the new Oracle JDK License started since April 16, 2019.
Click the Download Option as highlighted in Fig 3. It will ask to accept the License Agreement before starting the download as shown in Fig 4 and Fig 5. It might also ask to login to Oracle before starting the download.
Install Java 11
Double click the DMG file downloaded in the previous step to start installing Oracle JDK 11 on Mac. It will mount the DMG disk and shows the installer as shown in Fig 6 and Fig 7. Make sure that you have gone through the updated License Agreement of Oracle JDK.
Now double-click the installer to start installing Java 11 on Mac.
macOS Catalina — With the release of macOS 10.15, Apple introduced security checks used by the Gatekeeper to verify the content of distributed software. The Gatekeeper might show a security error. You may refer to How To Install Java 8 On Mac to resolve this issue.
The installer shows the Welcome Screen as shown in Fig 8.
Click the Continue Button to start the installation. It provides options to choose the installation type as shown in Fig 9.
You may change the installation location by clicking the Go Back Button. It did not allow me to change the installation location on macOS Catalina. Now click the Install Button to start installing Java 11 on Mac. It also asks for permission to complete the installation as shown in Fig 10.
It shows the success message after completing the installation as shown in Fig 11.
Now unmount the DMG image by right-clicking it as shown in Fig 12.
We can check the JDK version to confirm the installation as shown in Fig 13.
This is all about installing Oracle JDK 11 on Mac systems including macOS Sierra, High Sierra, Mojave, and Catalina.
Switch JDK
It might be required to switch the active Java in case multiple JDKs are installed on the same Mac machine. You can follow How To Switch Java Version On Mac.
Getting started with Java — Hello World
In this step, we will write, compile, and execute our first program in Java using the standard Hello World example.
Now write the first Java program as shown below, save the program as HelloWorld.java and exit the editor. Make sure that the class name and file name are the same.
class HelloWorld
public static void main( String[] args )
System.out.println( "Hello World !!" );
>
>
Now open the command prompt and navigate to the path where you have saved your Java program. Use the below-mentioned commands to compile and execute the program.
# Compile - Specify file name and extension
javac HelloWorld.java
# Execute - Spicy file name
java HelloWorld
# Output
Hello World !!
These are the easy to install steps required to install Oracle JDK on Mac and write, compile and execute the first Java program.
Summary
This tutorial provided all the steps required to install Oracle JDK 11 on Mac and also provided the steps required to compile and run the first Java program using a simple Hello World program.