Installing Oracle JDK on Windows subsystem for Linux

前端 未结 12 1932
半阙折子戏
半阙折子戏 2020-12-12 12:34

When trying to use the Linux version of Oracle\'s JDK on the latest Windows 10 build having support for bash, I am running into a problem with the prompt hanging whenever at

相关标签:
12条回答
  • 2020-12-12 13:12

    I'm confirming here that Oracle JDK Version 8u102, x64 for linux is installable ok on Windows 10 Insider Build 14905, released on 16th August 2016.

    Downloadable from here after accepting 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 the instructions here: 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've not yet had a chance to really stress this install, but this is better than the previous hangs.

    0 讨论(0)
  • 2020-12-12 13:15

    It seems that the problem occured with java oracle version, I have download the openJDK version and now it work

    0 讨论(0)
  • 2020-12-12 13:17

    Seems installing JDK8 is not working at the moment on Build#14316 of WSL. But trying to install JDK7 worked fine for me. Exploring the limits of this installation at the moment and will keep posted. Idea came from here : https://github.com/Microsoft/BashOnWindows/issues/196

    0 讨论(0)
  • 2020-12-12 13:19

    A lot of answers are recommending installing the Linux JDK even though they have a perfectly good Windows JDK. The beauty of WSL is preventing you from having to do things like this, as the file systems are interoperable. As long as you take the file extensions into account (outlined below), you would only have to install both for niche situations.

    Straightforward Method

    You can do this very simply by adding the following line of code to your .bashrc file, assuming that your Windows Environment variables are set correctly and WSL is installed:

    # Shared environment variables
    export JAVA_HOME=/mnt/d/Java/jdk11.0.4_10
    

    Just ensure that you change the directory to point to your JDK folder. In my case, it's in D:\Java\jdk11.0.4_10 which in WSL is /mnt/d/Java/jdk11.0.4_10

    Also, since you're using Windows binaries, you must specify the file type when running from a WSL bash shell:

    Example

    Calling Windows JDK from:

    CMD:

    javac MyClass.java
    java MyClass
    

    WSL:

    javac.exe MyClass.java
    java.exe MyClass
    

    Note WSL requires .exe since it is a Windows binary. When using the Linux distro of the OpenJDK, no extension is required..

    0 讨论(0)
  • 2020-12-12 13:24

    I had the same problem but I solve it with one command:

    sudo apt upgrade
    

    then run these 3 commands:

    sudo apt install default-jre
    sudo apt install openjdk-11-jre-headless
    sudo apt install openjdk-8-jre-headless
    
    0 讨论(0)
  • 2020-12-12 13:25

    I must be missing something... all I did was:

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

    output:

    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)
    
    0 讨论(0)
提交回复
热议问题