Install openjdk7 on Debian 7

The default JDK on Debian 7 is openjdk6, but it's so easy to install openjdk7:

1. Install

apt-get update
apt-get install openjdk-7-jre

Install source code:

sudo apt-get install openjdk-7-source

All the JDK versions can be found at /usr/lib/jvm/

2. Choose openjdk7 as the default JDK

update-alternatives --config java

and

cd /usr/lib/jvm
rm default-java
ln -s java-7-openjdk-amd64/ default-java

3. Add JAVA_HOME to your environment

append the following code to ~/.bashrc

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

(you can also append the above as a global setting in /etc/profile)

and then run this to active bash setting immediately:

source ~/.bashrc