I have installed Ubuntu 20.4 LTS on WSL. My windows 10 already have the JDK installed. Do I need to install JDK on ubuntu on WSL or can I use the Windows 10 JDK in the Ubuntu? How you do Java programming on WSL? Which is the proper way?
I was just wondering if I need to install all the development tools and binaries again on Linux won't it take a lot of space & hog a lot of CPU/Ram resources?
Press ctrl + shift + p , type "install extensions", press enter, and search for "java red hat", and install "Java Language Support" by Red Hat. Done! You're all set up to develop a Java project in Ubuntu in WSL!
As printed out, JDK is installed in folder /usr/lib/jvm/java-8-openjdk-amd64.
In a browser, go to the Java SE Development Kit 10 Downloads page and click Accept License Agreement. Under the Download menu, click the Download link that corresponds to the .exe for your version of Windows. Download the file jdk-10.
If you are going to develop in Linux, it's better to use the Linux version of Java. Technically, calling the Windows compiler from WSL will work in theory, but it might create unexpected problems like line endings, so I would just uninstall Windows Java and just install the JDK in Ubuntu.
Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:
$ sudo apt update
$ sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
$ java -version
The output should look something like this:
openjdk 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:
$ 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:
JAVA_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:
$ source /etc/environment
Verify that the JAVA_HOME environment variable was correctly set:
$ echo $JAVA_HOME
You should see the path to the Java installation:
/usr/lib/jvm/java-11-openjdk-amd64
for reference you can follow this link below How to Install Java on Ubuntu 20.04
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With