Introduction
This page is based on experience of setting up Java 8 on Ubuntu 14.04. Much of it may be applicable to other Java versions and distros.
Architecture
First we check which architecture we are running on.
Open a terminal and type the command :
arch
The output could be i686 or i386 for a 32 bits system or x86_64 for a 64 bits system.
Environment
On Ubuntu 14.04 and for historical reasons the Java commands are under the /usr/bin directory.
However in order to manage multiple version of Java the update-alternatives mechanism has been introduced. It allows multiple "providers" to be installed on the same machine, and configures which is the default.
This mechanism consists of two directories, /etc/alternatives who contains the symlinks and /var/lib/dpkg/alternatives who contains update-alternatives state information.
Let's see where is the java command:
user@machine$ ls -al /usr/bin/java lrwxrwxrwx 1 root root 22 Mar 12 2013 /usr/bin/java -> /etc/alternatives/java
As you can see the java command from /usr/bin will be resolved against the one contained in /etc/alternatives.
user@machine$ file /etc/alternatives/java /etc/alternatives/java: symbolic link to `/usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java'
The previous command shows us where lies the java command.
Now take a look in the file /var/lib/dpkg/alternatives/java:
manual /usr/bin/java java.1.gz /usr/share/man/man1/java.1.gz /usr/lib/jvm/java-8-openjdk-i386/jre/bin/java 1069 /usr/lib/jvm/java-8-openjdk-i386/jre/man/man1/java.1.gz /usr/lib/jvm/java-8-oracle/jre/bin/java 1070 /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java 1073
That file teaches us that there are several java command installed on this machine