Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:

Copy$ sudo apt update
$ sudo apt install openjdk-11-jdk

Once the installation is complete, you can verify it by checking the Java version:

Copy$ java -version

The output should look something like this:

Copyopenjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Set JAVA_HOME Environment Variable: OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java

Once you found the path of your preferred Java installation, open the /etc/environment file:

Copy$ sudo nano /etc/environment

Assuming you want to set JAVA_HOME to point to OpenJDK 11, add the following line, at the end of the file:

CopyJAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

For changes to take effect on your current shell you can either log out and log in or run the following source command:

Copy$ source /etc/environment

Verify that the JAVA_HOME environment variable was correctly set:

Copy$ echo $JAVA_HOME

You should see the path to the Java installation:

Copy/usr/lib/jvm/java-11-openjdk-amd64

for reference you can follow this link below How to Install Java on Ubuntu 20.04

Answer from Karam on Stack Overflow
Top answer
1 of 7
78

Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:

Copy$ sudo apt update
$ sudo apt install openjdk-11-jdk

Once the installation is complete, you can verify it by checking the Java version:

Copy$ java -version

The output should look something like this:

Copyopenjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Set JAVA_HOME Environment Variable: OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java

Once you found the path of your preferred Java installation, open the /etc/environment file:

Copy$ sudo nano /etc/environment

Assuming you want to set JAVA_HOME to point to OpenJDK 11, add the following line, at the end of the file:

CopyJAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

For changes to take effect on your current shell you can either log out and log in or run the following source command:

Copy$ source /etc/environment

Verify that the JAVA_HOME environment variable was correctly set:

Copy$ echo $JAVA_HOME

You should see the path to the Java installation:

Copy/usr/lib/jvm/java-11-openjdk-amd64

for reference you can follow this link below How to Install Java on Ubuntu 20.04

2 of 7
36

We can use the same JDK which is installed in Windows inside the wsl2. For that, we should add this to /etc/environment

CopyJAVA_HOME=/mnt/c/Program Files/Java/jdk-11.0.8/bin/

by adding this bin folder we may run regular commands but with .exe suffix eg: javac.exe hello.java java.exe hello.java

if you don't like that way then add alias like below:

Copyalias java='java.exe'
alias javac='javac.exe'

I think we can use any of the windows programs like this :)

🌐
Kontext
kontext.tech › home › blogs › java programming › install open jdk on wsl
Install Open JDK on WSL - Kontext Labs
February 2, 2021 - 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
Discussions

Java in wsl2?
Can I code in java in Vscode? yep If yes what extension should i use? the Java extension :) you are probably wanting to connect your VSCode to WSL. then all coding happens in WSL environment automatically. check this and to install Java to WSL in the first place, check this More on reddit.com
🌐 r/bashonubuntuonwindows
8
3
August 26, 2024
java - Installing Oracle JDK on Windows subsystem for Linux - Stack Overflow
It is perfectly okay to use/share the Windows JDK with WSL2 Linux, you just need to setup two things, JAVA_HOME and PATH in your Linux shell profile, in my case, ~/.bashrc. By default it is installed in here (version can be different) C:\Program Files\Java\jdk1.8.0_321 More on stackoverflow.com
🌐 stackoverflow.com
Has anyone succeeded running Java 8 on WSL?

At this time, I do not believe that it is possible to install any version of Java onto WSL mainly because of the current extremely limited functionality and stability with it being a feature that has not gone public.

More on reddit.com
🌐 r/windowsinsiders
4
2
April 13, 2016
Unable to install java-8-openjdk
I am attempting to install java-8-openjdk using the following commands: sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk Installation progress until: Installing new version of config file /... More on github.com
🌐 github.com
5
August 18, 2016
🌐
.NET Thailand
dotnetthailand.com › programming-cookbook › wsl-powershell-useful-scripts › install-java
Install Java on WSL2 | .NET Thailand
Execute the following commands to install default Java: Terminal window · sudo apt update · sudo apt search jdk · sudo apt install default-jdk · Alternatively, if you want to install a specific version, sepecify a package as the following command: Terminal window · sudo apt install ...
🌐
Medium
david-medragh.medium.com › install-java-8-on-ubuntu-22-04-on-wsl2-ad8f0260a331
Install Java 8 on Ubuntu 22.04 on WSL2 | by david medragh | Medium
January 11, 2022 - Install Java 8 on Ubuntu 22.04 on WSL2 sudo apt install openjdk-8-jdk Reading package lists… Done Building dependency tree Reading state information… Done The following packages were …
🌐
Medium
medium.com › @pierre.viara › install-java-on-windows-10-linux-subsystem-875f1f286ee8
Install Java on Windows 10 Linux subsystem | by Pierre Viara | Medium
October 10, 2020 - sudo apt install openjdk-11-jdk · Press enter or click to view image in full size · Once it is done, I invite you to type the following command line and check that Java JDK version is 11.X.X : java --version · Press enter or click to view ...
🌐
Freemansoft
joe.blog.freemansoft.com › 2020 › 10 › java-8-development-on-linuxws-with.html
Java 8 development on Linux/WSL with Visual Studio Code on Windows 10
October 29, 2020 - This means you probably will end up with Java 11 JDK installed in WSL2 Linux and in Windows. By default, applications will be Compiled with Java 11. You can target application compilation against versions other than the one used by the IDE. This is done by installing the needed Java versions on the Linux side and adding the Java installation locations to the list of targeting options in the settings. In my case, I'm targeting Java 8.
🌐
Reddit
reddit.com › r/bashonubuntuonwindows › java in wsl2?
r/bashonubuntuonwindows on Reddit: Java in wsl2?
August 26, 2024 -

Hey, I'm really new to linux developpement but I will be using this os for my studies so I'm triying to learn a few things. I installed wsl2 with ubuntu 22.04 instead of a dual boot because it seemed better. It works very well, especially with vscode. I even use X410 to have a perfect linux environnement.

However, I will be studiying java and I don't know how to proceed. I guess that my files will be stored in the wsl2 file system. Please explain me a few things :

Can I code in java in Vscode? If yes what extension should i use?

If no what should I intsall to code in java and how do I install it so i can run smoothly it with wsl2 files?

Thanks for explaining, really new to all of this so sorry if this is a stupid question...

Find elsewhere
🌐
DEV Community
dev.to › mumu › windows-subsystem-for-linux-java-setup-2b2b
Windows Subsystem for Linux Java Setup - DEV Community
May 24, 2021 - This will set up VSCode's WSL server and launch VSCode back in Windows for you. Press ctrl + shift + p, type "install extensions", press enter, and search for "java red hat", and install "Java Language Support" by Red Hat.
Top answer
1 of 14
93

I wanted to clarify that as of 9 December 2016, you most certainly can install Java 8 on Ubuntu Bash for Windows 10 and that @Karl Horton is correct.

You will need to install unzip sudo apt-get install unzip

Copy this script somewhere in your bash for windows session and make it executable (chmod +x filename). If you do not use a command line based editor such as vim then you will have windows line endings to deal with. you can use dos2unix or your preferred way of dealing with that. I just paste it into a file using vim.

 #!/bin/bash

set -ex

# UPDATE THESE URLs
export JDK_URL=http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
export UNLIMITED_STRENGTH_URL=http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip

# Download Oracle Java 8 accepting the license
wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
${JDK_URL}
# Extract the archive
tar -xzvf jdk-*.tar.gz
# clean up the tar
rm -fr jdk-*.tar.gz
# mk the jvm dir
sudo mkdir -p /usr/lib/jvm
# move the server jre
sudo mv jdk1.8* /usr/lib/jvm/oracle_jdk8

# install unlimited strength policy
wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
${UNLIMITED_STRENGTH_URL}
unzip jce_policy-8.zip
mv UnlimitedJCEPolicyJDK8/local_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/
mv UnlimitedJCEPolicyJDK8/US_export_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/oracle_jdk8/jre/bin/java 2000
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/oracle_jdk8/bin/javac 2000

sudo echo "export J2SDKDIR=/usr/lib/jvm/oracle_jdk8
export J2REDIR=/usr/lib/jvm/oracle_jdk8/jre
export PATH=$PATH:/usr/lib/jvm/oracle_jdk8/bin:/usr/lib/jvm/oracle_jdk8/db/bin:/usr/lib/jvm/oracle_jdk8/jre/bin
export JAVA_HOME=/usr/lib/jvm/oracle_jdk8
export DERBY_HOME=/usr/lib/jvm/oracle_jdk8/db" | sudo tee -a /etc/profile.d/oraclejdk.sh

And now I can do the following

fieldju@DESKTOP-LTL6MIC:~$ java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)                                                

The links and versions in the above script are likely to be out of date by the time you read this, so just head over to http://www.oracle.com/technetwork/java/javase/downloads/index.html accept the license so that their js lets you copy the new URLs and you should be good to go.

2 of 14
69

It seems in 2017 august the solution is simpler as suggested by @noah-david.

I was able to install Oracle JDK 8 from the “WebUpd8” team repository.

Instructions. To add the repository:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

To install:

sudo apt-get install oracle-java8-installer 
sudo apt install oracle-java8-set-default

After install

costin@amanta-win:/mnt/c/work$ java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

costin@amanta-win:/mnt/c/work$ which java
/usr/bin/java

costin@amanta-win:/mnt/c/work$ uname -a
Linux amanta-win 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 
  x86_64 x86_64 x86_64 GNU/Linux
🌐
GitHub
github.com › Microsoft › WSL › issues › 934
Unable to install java-8-openjdk · Issue #934 · microsoft/WSL
August 18, 2016 - I am attempting to install java-8-openjdk using the following commands: sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk Installation progress until: Installing new version of config file /...
Author   microsoft
🌐
Reddit
reddit.com › r/webdev › how to setup wsl2 with docker and intellij?
r/webdev on Reddit: How to setup WSL2 with docker and intellij?
March 4, 2026 -

I'm used to working on linux but is forced to use windows so I would like to set up WSL2 but haven't fully managed to do so. My tools available to use are intellij, java, mvn, angular, docker(docker desktop)

  1. I've installed everything I can in WSL2(mvn, java, angular and so on)

  2. My team uses Docker Desktop on macOs so I've installed that with wsl2 and ubuntu integration enabled. I can compile create images and containers in wsl2 using terminal commands. The first issue I have is that in linux i limited resources for docker using a slice. Docker desktop limits will affect my ubuntu wsl2 which I don't want. But if I don't limit it then the RAM usage will end up at 93% and I will notice lag in windows and slow compilation. Is it better to setup docker in wsl2 and skip docker desktop or are there any other alternatives?

  3. Intellij is installed locally on windows. Repos are placed in wsl2 path. In intellij i will open these repo and point the project sdk to java8 in wsl. However, I can't run unit tests with intellij. There will be an error "Failed to find compatible JDK". What is the best practice here? Do i need to download java for windows and point to that instead?

🌐
CSE CGI Server
cgi.cse.unsw.edu.au › ~cs2511 › 25T2 › setup › linux-wsl-setup
🐧 Linux/WSL (Ubuntu) | COMP2511 (25T2)
April 18, 2026 - Selection Command ----------------------------------------------- *+ 1 java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc40.x86_64/bin/java) 2 java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.12.0.7-2.fc40.x86_64/bin/java) Enter to keep the current selection[+], or type selection number: It is important you install exactly Gradle 8.8.
🌐
GitHub
gist.github.com › anh0701 › 58c49c39c6c945eea012df8d77a07ec0
How to Switch Between Multiple Java Versions (Windows, macOS, Linux, WSL) · GitHub
curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 17-tem sdk install java 8.0.392-tem sdk list java sdk use java 17-tem · Option 2: update-alternatives (Debian-based systems) sudo update-alternatives --config java · While SDKMAN is a great tool to manage Java versions, it's designed for Unix-based systems like Linux and macOS. In Windows, it only works inside a WSL (Windows Subsystem for Linux) environment — not in native PowerShell or CMD.
🌐
GitHub
gist.github.com › Sawaba › 22f3c3d4ec9a12dd972c2ecc71e4eca9
Java JDK 11 install script for Windows Subsystem for Linux (WSL) · GitHub
Anyone still using this: you can simply download it through the browser on your windows 10 machine, and then on your WSL navigate to /mnt/ which is where you drives are mounted, then you can copy the .tar.gz file from your mounted drive to your ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › java › openjdk › install
Install the Microsoft Build of OpenJDK | Microsoft Learn
Reinstall Oracle Java if you need to restore the Oracle registry keys. Run the EXE file from the command line. Use the selected features, as shown in the following example. .\<package>.exe /SILENT /SUPPRESSMSGBOXES /ALLUSERS /TASKS="FeatureEnvironment,FeatureJarFileRunWith" /DIR="C:\Program Files\Microsoft\" ... If installing for only the current user, use the flag /CURRENTUSER instead of /ALLUSERS.
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-264548 › Cannot-build-a-java-project-using-a-JDK-installed-in-WSL2
Cannot build a java project using a JDK installed in WSL2
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
CSE CGI Server
cgi.cse.unsw.edu.au › ~cs2511 › 26T1 › setup › linux-wsl-setup
🐧 Linux/WSL (Ubuntu) | COMP2511 (26T1)
April 18, 2026 - Setting up your local development environment for Java on Linux/WSL (Ubuntu).