Install Java

This is a step-by-step guide to install Java on Mac

Pavan Kulkarni

2 minute read

Install Java on Mac (manual process and using brew) system easily and quickly

Installing Java on Mac

Installing Java on Mac. - Manual Installation

At the end of this post you would have installed Java successfully on your mac machines.

  1. Download latest JDK from Oracle Website.
  2. This will download a .dmg file to your downloads direcotry.
  3. Locate this jdk-xx_osx-x64_bin.dmg and double click on it and follow the instructions on it.
  4. Verify if Java is installed (I’m using Java 8 for purpose of this blog

    Pavans-MacBook-Pro:~ pavanpkulkarni$ which java
    /usr/bin/java
    
  5. This will install jdk in path /Library/Java/JavaVirtualMachines

    Pavans-MacBook-Pro:~ pavanpkulkarni$ ls -l /Library/Java/JavaVirtualMachines
    total 0
    drwxr-xr-x  3 root  wheel  96 Dec  1 21:35 jdk1.8.0_152.jdk
    
  6. Add JAVA_HOME to ~/.bash_profile file

    export JAVA_HOME=$(/usr/libexec/java_home)
    export PATH=$PATH:$JAVA_HOME
    
  7. Verify if the path that you just added works properly.

    Pavans-MacBook-Pro:~ pavanpkulkarni$ java -version
    java version "1.8.0_152"
    Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
    Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
    

Installing Java on Mac - using brew

Installing Java on Mac using brew is a simple process. You need to have brew installed on your system as a pre-requisite. You can install brew from here

  1. Open terminal.
  2. Run the following commands

    Pavans-MacBook-Pro:~ pavanpkulkarni$ brew update
    Pavans-MacBook-Pro:~ pavanpkulkarni$ brew tap caskroom/cask
    Pavans-MacBook-Pro:~ pavanpkulkarni$ brew install Caskroom/cask/java
    
  3. This will install the latest version of jdk in /Library/Java/JavaVirtualMachines

  4. Verify installation by running

    Pavans-MacBook-Pro:~ pavanpkulkarni$ java -version
    java version "1.8.0_152"
    Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
    Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
    

Reference:

  1. https://en.wikipedia.org/wiki/Java_(programming_language)
  2. https://java.com/en/download/help/mac_install.xml
  3. https://brew.sh/
comments powered by Disqus