Installing Java 7 on Ubuntu

后端 未结 10 1364
温柔的废话
温柔的废话 2020-11-29 14:12

to install java I have always used the classic way from the terminal. I would like to install java manually. I placed the folder of the JDK on the desk and I set environment

相关标签:
10条回答
  • 2020-11-29 14:55

    I think you should consider Java installation procedure carefully. Following is the detailed process which covers almost all possible failures.

    Installing Java with apt-get is easy. First, update the package index:

    sudo apt-get update
    

    Then, check if Java is not already installed:

    java -version
    

    If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:

    sudo apt-get install default-jre
    

    You are fine till now as I assume.

    This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:

    sudo apt-get install default-jdk
    

    That is everything that is needed to install Java.

    Installing OpenJDK 7:

    To install OpenJDK 7, execute the following command:

    sudo apt-get install openjdk-7-jre 
    

    This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:

    sudo apt-get install openjdk-7-jdk
    

    Installing Oracle JDK:

    The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.

    You can still install it using apt-get. To install any version, first execute the following commands:

    sudo apt-get install python-software-properties
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    

    Then, depending on the version you want to install, execute one of the following commands:

    Oracle JDK 7:

    sudo apt-get install oracle-java7-installer
    

    Oracle JDK 8:

    sudo apt-get install oracle-java8-installer
    
    0 讨论(0)
  • 2020-11-29 15:02

    flup's answer is the best but it did not work for me completely. I had to do the following as well to get it working:

    1. export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
    2. chmod 777 on the folder
    3. ./gradlew build - Building Hibernate
    0 讨论(0)
  • 2020-11-29 15:03

    In addition to flup's answer you might also want to run the following to set JAVA_HOME and PATH:

    sudo apt-get install oracle-java7-set-default
    

    More information at: http://www.ubuntuupdates.org/package/webupd8_java/precise/main/base/oracle-java7-set-default

    0 讨论(0)
  • 2020-11-29 15:04

    This answer used to describe how to install Oracle Java 7. This no longer works since Oracle end-of-lifed Java 7 and put the binary downloads for versions with security patches behind a paywall. Also, OpenJDK has grown up and is a more viable alternative nowadays.

    In Ubuntu 16.04 and higher, Java 7 is no longer available. Usually you're best off installing Java 8 (or 9) instead.

    sudo apt-get install openjdk-8-jre
    

    or, f you also want the compiler, get the jdk:

    sudo apt-get install openjdk-8-jdk
    

    In Trusty, the easiest way to install Java 7 currently is to install OpenJDK package:

    sudo apt-get install openjdk-7-jre
    

    or, for the jdk:

    sudo apt-get install openjdk-7-jdk
    

    If you are specifically looking for Java 7 on a version of Ubuntu that no longer supports it, see https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher .

    0 讨论(0)
  • 2020-11-29 15:04

    Download java jdk<version>-linux-x64.tar.gz file from https://www.oracle.com/technetwork/java/javase/downloads/index.html.

    Extract this file where you want. like: /home/java(Folder name created by user in home directory).

    Now open terminal. Set path JAVA_HOME=path of your jdk folder(open jdk folder then right click on any folder, go to properties then copy the path using select all) and paste here.

    Like: JAVA_HOME=/home/xxxx/java/JDK1.8.0_201

    Let Ubuntu know where our JDK/JRE is located.

    sudo update-alternatives --install /usr/bin/java java /home/xxxx/java/jdk1.8.0_201/bin/java 20000
    sudo update-alternatives --install /usr/bin/javac javac /home/xxxx/java/jdk1.8.0_201/bin/javac 20000
    sudo update-alternatives --install /usr/bin/javaws javaws /home/xxxx/java/jdk1.8.0_201/bin/javaws 20000
    

    Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.

    sudo update-alternatives --set java /home/xxxx/sipTest/jdk1.8.0_201/bin/java
    sudo update-alternatives --set javac /home/xxxx/java/sipTest/jdk1.8.0_201/bin/javac
    sudo update-alternatives --set javaws /home/xxxxx/sipTest/jdk1.8.0_201/bin/javaws
    

    Now try:

    $ sudo update-alternatives --config java
    

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

      Selection    Path                                  Priority   Status
    ------------------------------------------------------------
    * 0            /usr/lib/jvm/java-6-oracle1/bin/java   1047      auto mode
      1            /usr/bin/gij-4.6                       1046      manual mode
      2            /usr/lib/jvm/java-6-oracle1/bin/java   1047      manual mode
      3            /usr/lib/jvm/jdk1.7.0_75/bin/java      1         manual mode
    

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

    update-alternatives: using /usr/lib/jvm/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in manual mode
    

    Repeat the above for:

    sudo update-alternatives --config javac
    sudo update-alternatives --config javaws
    
    0 讨论(0)
  • 2020-11-29 15:05

    PPA method no longer works.

    While Oracle Java 6 and 7 are not supported for quite a while, they were still available for download on Oracle's website until recently.

    However, the binaries were removed about 10 days ago (?), so the Oracle Java (JDK) 6 and 7 installers available in the WebUpd8 Oracle Java PPA no longer work.

    Oracle Java 6 and 7 are now only available for those with an Oracle Support account (which is not free), so I can't support this for the PPA packages.

    Source : http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html Dated : June 2017

    Oracle's download page says

    Updates for Java SE 7 released after April 2015, and updates for Java SE 6 released after April 2013 are only available to Oracle Customers through My Oracle Support (requires support login).

    Java SE Advanced offers users commercial features, access to critical bug fixes, security fixes, and general maintenance".

    I had to download it from Oracle archives - http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

    You need an account for this though.

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