Installing Oracle JDK on a Windows Subsystem for Linux

When I try to use the Linux JDK version for Linux in the latest version of Windows 10 with bash support, I have a problem with the invitation freezing when I try to call the java binary.

Typing even something as simple as java -version freezes, and I have to complete the process to resume control.

Has anyone got this job?

+73
java linux windows windows-subsystem-for-linux
Apr 07 '16 at 2:09
source share
9 answers

I wanted to clarify that from December 9, 2016, you can certainly 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 the Windows session and make it executable (chmod + x filename). If you are not using a command line editor such as vim, then you will have Windows line endings. you can use dos2unix or your preferred way to handle this. 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 go to http://www.oracle.com/technetwork/java/javase/downloads/index.html accept the license to their js let you copy the new urls and you should be good to go.

+70
Dec 10 '16 at 4:35
source share

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

I was able to install Oracle JDK 8 from the WebUpd8 command repository .

Instructions To add a repository:

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

For installation:

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

After installation

 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 
+61
Aug 10 '17 at 8:34 on
source share

I need to miss something ... all I did was:

 sudo apt-get update sudo apt-get install default-jdk java -version 

exit:

 java version "1.7.0_131" OpenJDK Runtime Environment (IcedTea 2.6.9) (7u131-2.6.9-0ubuntu0.14.04.2) OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode) 
+26
Jun 01 '17 at 13:36 on
source share

I used the script given by @fieldju, but it skipped some of the things that the script depends on, and copying / pasting the content causes the line endings / window carriage returns ( /r ) to be replaced by linux returns. Also, I found it much simpler to download the necessary zip codes and place them next to the script. Here is a complete list of what I did:

  • In bash type sudo apt-get install zip unzip to make sure uncip / zip is installed on the bash console
  • Download the latest version of Linux Java JDK from oracle (I have a 64-bit system, so I selected "Linux x64") and save it in a folder somewhere on your computer that you can go to bash NOTE. Do not change the file name to make sure that it works with the script
  • Download the unlimited strength strategy separately in the same folder as the last zip, again ensuring that you save the file name as it is.
  • Copy and paste the following script into notepad and save it as java_install_predownloaded.sh in the same folder next to the zip codes:

Script:

 #!/bin/bash # Extract the archive tar -xzvf 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 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 

This code is a modified version from @fieldju, which assumes that the zip codes are already loaded and are in the same folder as this .sh file

  1. because the file has a window carriage return, you need to make sure that they are replaced, so in bash go to where you saved java_install_predownloaded.sh and run the following command:

    sed 's/^M$//' java_install_predownloaded.sh > java_install_predownloaded_unix.sh

Then I also performed the following to ensure that there are no line endings from windows:

sed 's/\r$//' java_install_predownloaded_unix.sh > java_install_predownloaded_unix_final.sh

  1. After running these two lines, a file named java_install_predownloaded_unix_final.sh will be in the folder, which is our "cleaned" version without window windows, so you just need to run ./java_install_predownloaded_unix_final.sh in bash and see the magic happen. Hi Presto, you now have java installed on your bash instance on windows!
+8
Feb 08 '17 at 10:21
source share

It seems that installing JDK8 at the moment does not work on Build # 14316 WSL. But trying to install JDK7 worked fine for me. Exploring the limits of this installation at the moment and will keep in touch. The idea came from here: https://github.com/Microsoft/BashOnWindows/issues/196

+5
Apr 16 '16 at 6:11
source share

I confirm that Oracle JDK Version 8u102, x64 for Linux is installed on Windows 10 Insider Build 14905, released on August 16, 2016.

Loads from here after accepting the license

 C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version" OS Name: Microsoft Windows 10 Pro Insider Preview OS Version: 10.0.14905 N/A Build 14905 

I followed these instructions: wikiHow Oracle Java Install

 $ java -version java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode) $ javac -version javac 1.8.0_102 

I have not yet had the opportunity to really emphasize this installation, but it is better than the previous hangs.

+5
Aug 22 '16 at 1:52
source share

The steps I took to reinstall Oracle JDK 8 on my Bash (Windows 10):

  • sudo apt-get install python-software-properties
  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt-get update
  • sudo apt-get install oracle-java8-installer
  • Accept Licenses

    Picture

You are done! Check your java version using java -version and the expected output should look something like this:

 java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode) 

PS At the time of this writing, a stable version of Oracle 9 JDK was released, perhaps you could change step 4 above.




Link: https://poweruphosting.com/blog/install-java-ubuntu/

+4
Oct 24 '17 at 3:45
source share

It seems that the problem arose with the java version of oracle, I downloaded the openJDK version and now it works

0
Aug 03 '16 at 16:00
source share

it can work for Insider Preview build 14905, but it hangs on Windows 10 Pro build 14393. A good part of the problem is that Microsoft uses Ubuntu 14.0.4. 14.10 or later probably better supports Java 8.

0
Sep 25 '16 at 18:45
source share



All Articles