access_time 26 days ago languageEnglish
more_vert

Install Open JDK on WSL

visibility 12 comment 0

This article provides detailed steps to install Java Development Kit (JDK) on WSL. 

Step by step guide

The following steps are performed on a Debian WSL distro. You can apply similar steps on other distros like openSUSE, Ubuntu, etc.

infoThe following steps install OpenJDK 8; you can also install other compatible versions. 
  1.  Run the following command to update package index:
    sudo apt update
  2. Check whether Java is installed already:
    java --version

    The command will output the following text if Java is not installed yet: -bash: java: command not found.

  3. Install OpenJDK via the following command:
    sudo apt-get install openjdk-8-jdk

    Type Y to continue when asked. 

    Wait until the installation is completed.

  4. Check the version again:
    ~$ java -version
    openjdk version "1.8.0_275"
    OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-1~deb9u1-b01)
    OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

Configure JAVA_HOME

Configure JAVA_HOME environment variable is optional but I highly recommend it especially if you want to install Hadoop, Spark, Hive, HBase or any other Java based frameworks. 

To do this, we need to find out where JDK is installed:

$ readlink -f $(which java)
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
As printed out, JDK is installed in folder /usr/lib/jvm/java-8-openjdk-amd64.
Run the following command to edit .bashrc file:
vi ~/.bashrc
Add the following line to the content:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Save the file and then run the following command:

source ~/.bashrc

Run the following command to make sure it is effective:

~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn or Twitter.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 53
thumb_up 0
access_time 3 months ago
visibility 67
thumb_up 0
access_time 3 months ago
visibility 8
thumb_up 0
access_time 27 days ago