Installing JDK 7 on debian

37,641

Solution 1

The packages available for installation as well as already installed ones can be listed with the command

apt-cache --names-only search openjdk

The first column is the package name which is to be provided as argument for apt-get install. For example:

apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib

Solution 2

Manual installation

Basically one just needs to fetch the archive, extract files from it and setup some environment variables to make the installed JDK the default one.

With root permissions perform the following actions:

# Installing the JDK in /opt
cd /opt

# Fetch the JDK
wget http://download.oracle.com/otn-pub/java/jdk/7u60-b19/jdk-7u60-linux-x64.tar.gz

# Extract files from it
tar xvf jdk-7u60-linux-x64.tar.gz
rm jdk-7u60-linux-x64.tar.gz

The JDK is already ready to be used actually.

If you want to make this JDK the system-wide default, run the following with root permissions:

update-alternatives --remove java /usr/bin/java
update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_60/jre/bin/java

update-alternatives --remove javac /usr/bin/javac
update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_60/bin/javac

If you only want to make the JDK available to one user, you need to add the following lines to the end of .bashrc in the home directory:

PATH=/opt/jdk1.7.0_60/bin:/opt/jdk1.7.0_60/jre/bin:$PATH
export PATH

Solution 3

There is a nice answer here that worked out pretty well for me. I'm going to outline it below.

First, you will need to inform your Squeeze installation's APT that it should look at a repository that does offer instances of Java 7 (and beyond). This includes adding the repositories to your sources.list, adding the key, and then updating APT indices.

To make things simpler, we will first login to your sudo prompt:

sudo -

or

sudo -i

Then we will add the repositories:

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list

Each line will also output the newly added repository, so don't panic if you get some output.

Next, we should fetch the key for the repositories so that APT can trust packages it downloads from the newly introduced sources:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

After this, 1 key should have been imported.

Then, we will update APT indices:

apt-get update

and don't forget to exit the privileged session:

exit

Now, if you do:

sudo aptitude search jdk

you will see a list that will contain Java 7 and 8 versions from Oracle and the OpenJDK set. There is also a meta package offered by Oracle that will run an installer for you: oracle-java7-installer. You could install that and expect it to install JDK7 for you.

Should you have a previous installation of Java on your machine that you would like to be replaced by this one as the default, there is also a convenience dummy package that will do just that: oracle-java7-set-default.

Remember that this does not actually erase the previous installation. It will just rewrite the links so that JDK7 becomes the default JDK.

Finally, you can confirm your installation by typing in:

$ java -version

Which should output something along the lines of:

java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

Solution 4

Debian squeeze apparently does not include OpenJDK 7 yet.

Availability of OpenJDK 7 in Debian: http://packages.debian.org/search?keywords=openjdk-7-jdk

As you might know, early version of Java 7 had a number of issues. Ranging from excessive memory use with AWT to security issues (ok, IIRC these also affected Java 6). So, at the time Debian squeeze was released, OpenJDK 7 was not ready to be used (not yet "stable").

So you have three options:

  • Upgrade to the next version, wheezy
  • Try to build the openjdk-7 package from wheezy on squeeze (should work, but it is not on backports yet!)
  • Manually install openjdk-7

The first option has one big big big advantage: you get automatic security updates. And if you need more up to date software than is in current stable, you may have to use the next-stable version.

With the second option, you should at least have an easy way of making Java 7 your default java. With the unmanaged installation (option 3) this is much more tricky to get working reliably.

Anyway, I would go with the first option.

Share:
37,641

Related videos on Youtube

Ujjwal-Nadhani
Author by

Ujjwal-Nadhani

Updated on September 18, 2022

Comments

  • Ujjwal-Nadhani
    Ujjwal-Nadhani over 1 year

    So I just rented a dedicated server running Debian, and I know nothing about Linux.

    Anyway, I want to install the JDK 7, first I connected through SSH and granted myself administrator rights by typing su -.

    Then I typed apt-get install openjdk-7-jdk, however I get a message saying that the package openjdk-7-jdk cannot be found

    Am I doing something wrong?

    • goldilocks
      goldilocks over 11 years
      Which version of debian is this? If it is old, there may not be an openjdk 7 compiled against it, so you won't find one -- although this seems unlikely. In any case, you should be able to use the Oracle JDK 7 for linux, just find the link then use wget via ssh.
    • Ujjwal-Nadhani
      Ujjwal-Nadhani over 11 years
      debian v6.0.0 (64BITS)
  • xrfang
    xrfang over 11 years
    Sure. But how does this answer the question? The OP has the correct package name already.
  • Ujjwal-Nadhani
    Ujjwal-Nadhani over 11 years
    Who filled this cache with sofware to install? how can I add some to it? apparently the JDK7 is not in it.
  • Remon
    Remon over 11 years
    please show the output of apt-cache -n search openjdk
  • Ujjwal-Nadhani
    Ujjwal-Nadhani over 11 years
    'add-apt-repository' is not a known command
  • Majid Azimi
    Majid Azimi about 11 years
    wheezy does not include openjdk-7 too.