Java Core
    Java - Overview
    What is new in Java 21
    What is new in Java 17
    What is new in Java 11
    Java - JVM
    Java - Deprecated
    Java - Numbers
    Java - String
    Java - Time
    Java - Collections
    Java - Lambda
    Java - Exceptions
    Java - Switch
    Java - IO
    Java - Jar
    Java - Generics
    Java - Environment
    Java - Concurrency
    Java - Trouble Shooting
    Java - Install
    Java - Misc

Java - Install

Updated: 2022-08-06

Install Prebuilt OpenJDK

Download OpenJDK from

Extract the package:

$ tar xvzf openjdk-<version>_bin.tar.gz

Add this to ~/.bash_profile or ~/.bashrc:

export JAVA_HOME=/path/to/jdk-<version>


Then "source" it:

$ . ~/.bashrc

Verify that Java is correctly installed:

$ java -version

Install on macOS

Download JDK

Download JDK from:

If you are using .tar.gz, it would be similar to the above. If you are installing .dmg on macOS, JDK should be installed in this folder:


Use brew

Search for Java

$ brew search java

Check the version:

$ brew info java

Install Java

$ brew install java

Set JAVA_HOME based on javac

export JAVA_HOME="$(dirname $(dirname $(realpath $(which javac))))"