Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
2  
try this. run apt-get update and then run the same command again. –  harish.venkat Dec 19 '12 at 17:54
2  
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. –  goldilocks Dec 19 '12 at 19:15
    
debian v6.0.0 (64BITS) –  Eildosa Dec 19 '12 at 21:36

4 Answers 4

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
share|improve this answer
1  
Sure. But how does this answer the question? The OP has the correct package name already. –  ire_and_curses Dec 19 '12 at 17:57
1  
Who filled this cache with sofware to install? how can I add some to it? apparently the JDK7 is not in it. –  Eildosa Dec 19 '12 at 18:09
    
please show the output of apt-cache -n search openjdk –  harish.venkat Dec 19 '12 at 18:11
    
openjdk-6-dbg - Java runtime based on OpenJDK (debugging symbols) openjdk-6-demo - Java runtime based on OpenJDK (demos and examples) openjdk-6-doc - OpenJDK Development Kit (JDK) documentation openjdk-6-jdk - OpenJDK Development Kit (JDK) openjdk-6-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless) openjdk-6-jre-lib - OpenJDK Java runtime (architecture independent libraries) openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-6-source - OpenJDK Development Kit (JDK) source files openjdk-6-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark –  Eildosa Dec 19 '12 at 18:16
1  
if you want openjdk-7 use add-apt-repository ppa:openjdk/ppa and then apt-get update and then apt-get install openjdk-7-jdk openjdk-7-doc openjdk-7-jre-lib –  harish.venkat Dec 19 '12 at 18:18

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|improve this answer
    
wheezy does not include openjdk-7 too. –  Majid Azimi Feb 25 '13 at 6:29
    
@MajidAzimi sure it does: packages.debian.org/wheezy/openjdk-7-jdk - you should however make sure to get version 7u3-2.1.6-1 which includes the recent security fixes. –  Anony-Mousse Feb 25 '13 at 8:10

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)
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.