Installing Java 7 on Ubuntu

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 variables (PATH, CLASSPATH and JAVA_HOME). From the terminal, if I type java -version I get printed

foralobo@ubuntu-vincy:~$ java -version java version "1.7.0_21" Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode) 

But when I try to install eclipse or netbeans, the system warns by saying that there is no java installed on the machine.

What is missing to compleatare manual installation? (Ubuntu 13.04)

4

10 Answers

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 .

16
sudo apt-get update sudo apt-get install openjdk-7-jdk 

and if you already have other JDK versions installed

sudo update-alternatives --config java 

then select the Java 7 version.

3

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:

3

Download java jdk<version>-linux-x64.tar.gz file from .

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 
5

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 

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 : 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 -

You need an account for this though.

1

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

Oracle Java 1.7.0 from .deb packages

wget chmod +x oab-java.sh sudo ./oab-java.sh -7 sudo apt-get update sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source sudo apt-get dist-upgrade 

Workaround for 1.7.0_51

There is an Issue 123 currently in OAB and a pull request

Here is the patched vesion:

wget chmod +x oab-java.sh sudo ./oab-java.sh -7 sudo apt-get update sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source sudo apt-get dist-upgrade 

Oracle as well as modern versions of Ubuntu have moved to newer versions of Java. The default for Ubuntu 20.04 is OpenJDK 11 which is good enough for most purposes.

If you really need it for running legacy programs, OpenJDK 8 is also available for Ubuntu 20.04 from the official repositories.

If you really need exactly Java 7, the best bet as of 2020 is to download a Zulu distribution. The easiest to install if you have root privileges is the .DEB version, otherwise download the .ZIP one.

Open Applicaction -> Accessories -> Terminal Type commandline as below... sudo apt-get install openjdk-7-jdk Type commandline as below... apt-cache search jdk (Note: openjdk-7-jdk is symbolically used here. You can choose the JDK version as per your requirement.) For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path... export JAVA_HOME=/usr/lib/jvm/java-7-openjdk (Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.) For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path... export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin (Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.) Check for "open jdk" installation, just type command in "Terminal" as shown below javac -version 

You Might Also Like