Setting JAVA_HOME to proper value

There were a lot of times, when I needed to set up more than one java version. We should add the following line at the beginning of the file /etc/environment

JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

This way every-time you start the system it will read which java has been selected by update-alternatives

Also if you change your java version often you can add it to your .bashrc file so everytime you login in a shell it will read and set JAVA_HOME to the proper directory.