How can i install jdk7 on ubuntu 18.04 lts 64bit? [duplicate]

Solution 1:

Download the JDK for Linux 32-bit or 64-bit (for example: jdk-7u80-linux-x64.tar.gz)

  1. Navigate to ~/Downloads:

    cd /home/"your_user_name"/Downloads
    
  2. Create a a directory in /usr/local where java will reside and copy tarball there:

    sudo mkdir -p /usr/local/java
    sudo cp -r jdk-7u80-linux-x64.tar.gz /usr/local/java/
    
  3. Navigate to /usr/local/java:

    cd /usr/local/java
    
  4. Extract the tarball:

    sudo tar xvzf jdk-7u80-linux-x64.tar.gz
    
  5. Check if tarball has been successfully extracted:

    ls –a
    

    You should see jdk1.7.0_80.

  6. Open /etc/profile with sudo privileges:

     sudo nano /etc/profile
    
  7. Scroll down to the end of the file using arrow keys and add the following lines below at the end of /etc/profile file:

     JAVA_HOME=/usr/local/java/jdk1.7.0_80
     JRE_HOME=/usr/local/java/jdk1.7.0_80 
     PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
    
     export JAVA_HOME
     export JRE_HOME
     export PATH
    
  8. Update alternatives:

    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_80/bin/java" 1
    sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_80/bin/javac" 1
    sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_80/bin/javaws" 1
    sudo update-alternatives --set java /usr/local/java/jdk1.7.0_80/bin/java
    sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_80/bin/javac
    sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_80/bin/javaws
    
  9. Reload profile:

    source /etc/profile
    
  10. Verify installation:

    java -version
    

    You should receive a message which displays:

    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
    

Solution 2:

Update -

Since the bottom fix is no longer working, try this -

  1. Visit http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
  2. Download the desired java package. i.e, 32bit(x86) or 64bit(x86_64)
    note: you'll need to sign in to download it as pointed by @Kendzi in the comment below
  3. Change location to your downloads folder(or to where you've download the archive) cd ~/Downloads
  4. Extract the archive tar -xvzf jdk-7u80-linux-x64.tar.gz
  5. There should be a new folder available now, named - jdk1.7.0_80 or something similar
  6. Move the folder to a desired location.
    Move it to the default location(recommended) - sudo mv jdk1.7.0_80 /usr/lib/jvm/ note : create the jvm folder if it does not exist with sudo mkdir /user/lib/jvm

  7. Assuming the folder has now been moved to /usr/lib/jvm,
    1. If this is the absolute first time you're installing Java, just run the update-alternatives command to update the preferred Java as default update-alternatives --config java and select the option number for Java 7
    2. if you have already installed Java once check whether a symlink exists in /etc/alternatives sudo ls -al /etc/alternatives/java
      If you see a listing similar to the following lrwxrwxrwx 1 root root 46 Jun 20 21:51 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
      The symlink exists and only needs to be updated using the command - update-alternatives --config java
      This will list the available Java executable files available in your system, like so -
      (including the JDK 7 executable you've placed in /usr/lib/jvm) Java - update-alternatives --config java Note the asterisk(*) next to option 1. This indicates the default version of Java being used.
      If the JDK 7 location is listed here, enter the option number and hit enter to set JDK 7 as the default.
    3. If for some reason no listing is provided after running the update-alternatives command, check if the symbolic links(symlink) are setup properly sudo ls -al /etc/alternatives/java
      if no file is found, create the symlink - sudo ln -s /etc/alternatives/java /usr/lib/jvm/jdk1.7.0_80/bin/java
      Also, create a symlink in /usr/bin to ensure availability of the Java executable in the terminal. So first check if the file exists in /usr/local- sudo ls -al /usr/bin/java if no file is found, create the symlink - sudo ln -s /usr/bin/java /etc/alternatives/java

  8. Finally set the JAVA_HOME variable for application use by editing file /etc/environment sudo gedit /etc/environment
    and add the JAVA_HOME variable like so - JAVA_HOME="/usr/bin/java" save and close the file.

    Reload the environment file using command - source /etc/environment

(Fix is no longer working as noted by @Christian Rodriguez)

After downloading the the Oracle JDK 7 package from Oracle's website, place the file in the location -

/var/cache/oracle-jdk7-installer/<Oracle JDK 7>

(create the oracle-jdk7-installer folder if it is not already present)

Then open a terminal(shortcut: Ctrl+Alt+t) and execute each of the following commands(one after the other) -

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

To verify the installation was successful, execute the following command -

    java -version

You should see a message similar to the one shown below -

    java version "1.7.0_76"
    Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

Refer

  1. http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
  2. http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html

for more information.