logo

Java - Install

Last Updated: 2022-08-06

Install Prebuilt OpenJDK

Download OpenJDK from http://jdk.java.net/

Extract the package:

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

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

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

PATH=$JAVA_HOME/bin:$PATH

Then "source" it:

$ . ~/.bashrc

Verify that Java is correctly installed:

$ java -version

Install on macOS

Download JDK

Download JDK from: http://www.oracle.com/technetwork/java/javase/downloads/index.html

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:

/Library/Java/JavaVirtualMachines/

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))))"