How to install JDK 11 under Ubuntu?

前端 未结 8 1856
你的背包
你的背包 2020-12-12 20:04

So Java 11 is out. Does anybody know how to install it (OpenJDK from Oracle) from the command line?

I would like to see something like it was before for Oracle Java

相关标签:
8条回答
  • 2020-12-12 20:29

    sudo apt-get install openjdk-11-jdk

    after this, try

    java -version

    to make sure java version is 1.11.x, if found old one or different, check below command to see the available jdks,

    sudo update-java-alternatives --list

    you should see something like below,

    java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64

    java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64

    you can see java 1.11 available from above list, use below command to set java 11 to default,

    sudo update-alternatives --config java

    for above command, you will get something like below and also, will ask for an option to set,

    There are 3 choices for the alternative java (providing /usr/bin/java).

    Selection Path Priority Status


    0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode

    1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode

    *2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

    3 /usr/lib/jvm/jdk1.8.0_211/bin/java 0 manual mode

    Press to keep the current choice[*], or type selection number:

    you can select desired selection number, my case it's 0

    for javac,

    sudo update-alternatives --config javac

    will result something like below,

    There are 3 choices for the alternative javac (providing /usr/bin/javac).

    Selection Path Priority Status


    0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode

    1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode

    *2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
    3 /usr/lib/jvm/jdk1.8.0_211/bin/javac 0 manual mode

    Press to keep the current choice[*], or type selection number:

    in my case, it's 0 again

    after above steps, try

    java -version

    it will display something like below,

    openjdk version "11.0.4" 2019-07-16

    OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)

    OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed > mode, sharing)

    0 讨论(0)
  • 2020-12-12 20:30

    In Ubuntu, you can simply install Open JDK by following commands.

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

    You can check the java version by following the command.

    java -version
    

    If you want to install Oracle JDK 8 follow the below commands.

    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java8-installer
    

    If you want to switch java versions you can try below methods.

    vi ~/.bashrc and add the following line export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221 (path/jdk folder)

    or

    sudo vi /etc/profile and add the following lines

    #JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
    JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    export PATH=$JAVA_HOME/bin:$PATH
    export JAVA_HOME
    export JRE_HOME
    export PATH
    

    You can comment on the other version. This needs to sign out and sign back in to use. If you want to try it on the go you can type the below command in the same terminal. It'll only update the java version for a particular terminal.

    source /etc/profile
    

    You can always check the java version by java -version command.

    0 讨论(0)
  • 2020-12-12 20:34

    I came here looking for the answer and since no one put the command for the oracle Java 11 but only openjava 11 I figured out how to do it on Ubuntu, the syntax is as following:

    sudo add-apt-repository ppa:linuxuprising/java
    sudo apt update
    sudo apt install oracle-java11-installer
    
    0 讨论(0)
  • 2020-12-12 20:39

    First check the default-jdk package, good chance it already provide you an OpenJDK >= 11.
    ref: https://packages.ubuntu.com/search?keywords=default-jdk&searchon=names&suite=all&section=all

    Ubuntu 18.04 LTS +

    So starting from Ubuntu 18.04 LTS it should be ok.

    sudo apt update -qq
    sudo apt install -yq default-jdk
    

    note: don't forget to set JAVA_HOME

    export JAVA_HOME=/usr/lib/jvm/default-java
    mvn -version
    

    Ubuntu 16.04 LTS

    For Ubuntu 16.04 LTS, only openjdk-8-jdk is provided in the official repos so you need to find it in a ppa:

    sudo add-apt-repository -y ppa:openjdk-r/ppa
    sudo apt update -qq
    sudo apt install -yq openjdk-11-jdk
    

    note: don't forget to set JAVA_HOME

    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    mvn -version
    
    0 讨论(0)
  • 2020-12-12 20:40

    For anyone running a JDK on Ubuntu and want to upgrade to JDK11, I'd recommend installing via sdkman. SDKMAN is a tool for switching JVMs, removing and upgrading.

    SDKMAN is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.

    Install SDKMAN

    $ curl -s "https://get.sdkman.io" | bash
    $ source "$HOME/.sdkman/bin/sdkman-init.sh"
    $ sdk version
    

    Install Java (11.0.3-zulu)

    $ sdk install java
    
    0 讨论(0)
  • 2020-12-12 20:43

    I created a Bash script that basically automates the manual installation described in the linked similar question. It requires the tar.gz file as well as its SHA256 sum value. You can find out more info and download the script from my GitHub project page. It is provided under MIT license.

    0 讨论(0)
提交回复
热议问题