13

I upgrade my system to ubuntu 18.04 lts, but I work on projects that require JDK 7. How can i install jdk7 on ubuntu 18.04 lts 64bit?

0

3 Answers 3

35

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)
    
4
  • Thank you, i used your instructions to install JDK8 and it worked well. Thanks! A few minor points though: If i try to download JDK7 it wants me to log in to an Oracle account. Also steps 8-14 are only needed if the user already has Java installed
    – sunyata
    Aug 2, 2018 at 12:10
  • 2
    @sana wow that is a high quality answer!
    – tatsu
    Apr 18, 2019 at 9:58
  • I think the export mush be export JAVA_HOME
    – Tri
    Jun 28, 2019 at 6:20
  • 1
    This does not install OpenJDK, it installs Oracle's JDK.
    – Supernovah
    Aug 20, 2019 at 5:17
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.

1
0

Looks like regular JDK are only available to Oracle Customers after creating account:

http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

But that link is still working:

http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-7-jdk-7u21-downloads-1956231.html

Simply chose "java_ee_sdk-7-jdk7-linux-x64.sh" and install it manually.

5
  • Thank you for your answer . but how can i install it ?
    – sana
    May 10, 2018 at 9:06
  • - mark it as executable chmod +x java_ee_sdk-7-jdk7-linux-x64.sh and run it by ./java_ee_sdk-7-jdk7-linux-x64.sh that run UI with wizzard
    – Kendzi
    May 10, 2018 at 9:27
  • I am a new Ubuntu user. how can i mark it executable ?
    – sana
    May 10, 2018 at 9:39
  • 1
    You need to open terminal, go to directory where you downloaded file and execute command: chmod +x java_ee_sdk-7-jdk7-linux-x64.sh later run install with executing second command ./java_ee_sdk-7-jdk7-linux-x64.sh
    – Kendzi
    May 10, 2018 at 9:51
  • when i run ../java_ee_sdk-7-jdk7-linux-x64.sh i get the folloing error :Could not locate a suitable jar utility. Please ensure that you have Java 7 or newer installed on your system and accessible in your PATH or by setting JAVA_HOME
    – sana
    May 10, 2018 at 10:11

Not the answer you're looking for? Browse other questions tagged .