How to Install Java in macOS
- Prerequisites to Install Java in macOS
- Evaluate the Current JDK Version in Java
- JDK Download Instructions Using the UI Interface
- JDK Download Instructions Using the Command Prompt
Prerequisites to Install Java in macOS
As a part of the system requirements, the system must have an intel-based microprocessor with macOS(10.x or later versions) as an operating system running over it. In addition, the system must have administrative privileges because JDK must be installed systemwide and not for the specific user group or a user profile. Lastly, the system needs a 64-bit web browser, such as Safari.
Evaluate the Current JDK Version in Java
If a user uses a command prompt to run the Java application, one should first check the default version of JDK using the command java -version
. A system can have more than one Java installed over it.
After running the given command in the prompt, you’ll know that JDK is already installed if a specific version is displayed. However, if you encounter the command not found
message, there’s no JDK that’s previously installed.
JDK Download Instructions Using the UI Interface
-
Follow the link to download the desired version specific to the operating system https://www.oracle.com/java/technologies/downloads/.
-
Download the JDK
.dmg
file for macOS. -
Click the
accept
button for the license agreement. -
From the download section, double-click on the
.dmg
file to start its execution. -
A finder window appears that has an open box icon, and the
.pkg
package file name comes. -
Double-click on the
.pkg
file to start the installation. -
Initially, a pop-up window appears.
-
Click the
continue
button. -
The type dialog box appears.
-
Click the
install
button. -
The progress bar now appears over the dialog box with a message over it to enter the system credentials.
-
Enter the username and password and click the
install
button to install the application. -
Once successful installation takes place, delete the
.dmg
file to save disk space.
JDK Download Instructions Using the Command Prompt
-
Open the command prompt.
-
Run the command to install the JDK from the Homebrew package manager,
brew tap adoptopenjdk/openjdk
. -
To install Java 8, run the command,
brew cask install adoptopenjdk8
, to install the version. -
Once the JDK gets successfully downloaded, open the
.bash_profile
file. -
Use the
nano ~/.bash_profile
command to open the file. -
Add the Java home path to the file using the command,
export JAVA_HOME=/usr/libexec/java_home -v1.8
. -
Press Ctrl+X to exit the file.
-
Reload the
.bash_profile
to take effect. -
Check the Java version from the command prompt using
java -version
OR$JAVA_HOME
.
Rashmi is a professional Software Developer with hands on over varied tech stack. She has been working on Java, Springboot, Microservices, Typescript, MySQL, Graphql and more. She loves to spread knowledge via her writings. She is keen taking up new things and adopt in her career.
LinkedIn