Ubuntu: OpenJDK 8 - Unable to locate package

后端 未结 6 1924
遇见更好的自我
遇见更好的自我 2020-12-12 10:44

So I just installed Ubuntu, and this is my first time working in a Linux environment, so bear with my noobishness here.

Anyway, I downloaded the Java 8 JDK directly

6条回答
  •  难免孤独
    2020-12-12 11:17

    As you can see I only have java 1.7 installed (on a Ubuntu 14.04 machine).

    update-java-alternatives -l
    java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
    

    To install Java 8, I did,

    sudo add-apt-repository ppa:openjdk-r/ppa
    sudo apt-get update
    sudo apt-get install openjdk-8-jdk
    

    Afterwards, now I have java 7 and 8,

    update-java-alternatives -l
    java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
    java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
    

    BONUS ADDED (how to switch between different versions)

    • run the follwing command from the terminal:

    sudo update-alternatives --config java

    There are 2 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                            Priority   Status
    ------------------------------------------------------------
      0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
      1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
    * 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1069      manual mode
    
    Press enter to keep the current choice[*], or type selection number:
    

    As you can see I'm running open jdk 8. To switch to to jdk 7, press 1 and hit the Enter key. Do the same for javac as well with, sudo update-alternatives --config javac.

    Check versions to confirm the change: java -version and javac -version.

提交回复
热议问题