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
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
1 key should have been imported.
Then, we will update APT indices:
and don't forget to exit the privileged session:
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:
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)