Installing Oracle JDK on Windows subsystem for Linux
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.
What is the proper way of using JDK on WSL2 on Windows 10?
There is not a "proper" (as in supported or recommended by JDK providers) way to install or use Java on WSL. I could not find any official recommendations.
However, it is possible to either install and use Oracle JDK for Windows installation from WSL, or install OpenJDK Java into your WSL world from the Ubuntu package manager.
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 ?
See above. But note that you are only going to "hog CPU/RAM" if you are running both kinds of JVM at the same time.
References:
- Installing Oracle JDK on Windows subsystem for Linux
- Java JDK 11 install script for Windows Subsystem for Linux (WSL)
- Windows Subsystem for Linux Java Setup ... using the Ubuntu package system.
(There are many more articles on this topic if the above don't address your concerns.)
I got syntax error while installing jdk on my WSL Kali linux
Based on the error message that bash gives for your /etc/profile.d/oraclejdk.sh it looks like you just need to double-quote the entire value assigned to your PATH variable.
Instead of this:
export PATH=/usr/local/sbin:/usr/local/bin...
Try this:
export PATH="/usr/local/sbin:/usr/local/bin..."
Note that double quotes are required because some of your folder names have white space. As a result bash sees everything after the first space as another expression and not part of the PATH value. Also the "(" character has special meaning to bash so it needs to be double quoted also.
Is it possible to install IBM java on Windows Subsystem for Linux (WSL) - Ubuntu?
UPDATE - January 2018
Microsoft has made significant improvements to the underlying technology and memory management in WSL, and the latest versions of Windows 10 Insiders work well with the JVM. It is not as fast as a native Linux machine, but it is now possible to work in the WSL environment without suffering form major delays for simple command execution. The answer is now yes, but you must have Windows 10 build 17074 or better in order to have decent performance.
--- ORIGINAL ANSWER - Dec, 2017 ---
After some research, I found out that the answer is both Yes and No:
Yes, because the JDK installs correctly and functions as expected (other than speed) in the platform without any special modifications or configuration.
No, because due to the architecture of the WSL, certain memory mapping functions work different in WSL than in a fully native Linux environment. Users have reported very slow performance using Haskell, and it looks like Java suffers from the same problem too. There have been significant improvements in Windows 10 releases since the summer of 2017, but it is still slow compared to a native system.
Microsoft is still actively working on this issue, though, and the "No" part of this answer may be fixed in the near future.
Related Topics
Firebase Firestore Get Data from Collection
Start a Jar File Like Service in Linux
How to Convert a Char to a String
Execute Another Jar in a Java Program
How to Store More Than One String in a Map
Mod in Java Produces Negative Numbers
Load Chrome Profile Using Selenium Webdriver Using Java
Good Hash Function for Strings
Preemptive Basic Authentication with Apache Httpclient 4
How to Derive Module Descriptor: Provider {Class X} Not in Module
How to Paginate Queries by Combining Query Cursors Using Firestorerecycleradapter
How to Debug Java -Jni Using Gdb on Linux
Nullpointerexception in Java with No Stacktrace
Java' Is Not Recognized as an Internal or External Command