When you download the
.bin file or the
.tar.gz file from Oracle, then whenever you run it or unzip it, it'll create some folder called
jdk1.x.0_yz, where
x is the major version of Java and
yz is the update version. If you move that folder to
/usr/lib/jvm then the directory structure of
/usr/lib/jvm will look like this:
Code:
:~$ ls -1 /usr/lib/jvm
default-java
java-1.6.0-openjdk
java-1.7.0-openjdk-amd64
java-6-openjdk
java-7-openjdk-amd64
java-7-openjdk-common
jdk1.4.2_19
jdk1.5.0_22
jdk1.6.0_35
jdk1.7.0_07
That's really it for how you setup Java.
As for setting up the script itself, if you've copied the inner part of that function into a shell script called
javahome.sh and you've placed that shell script on your path, then
javahome.sh 5 will switch you to
jdk1.5.0_22. For me, I just copied the whole
javahome() function into my
.bash_aliases file in my home folder, which gets loaded whenever I open a shell.
That being said, I suspect that the script only works reliably if there's only one update version for each major release (so only one 1.4, only one 1.5, only one 1.6, only one 1.7). If you have more than one, then it'll wind up choosing the last one that is seen in the for loop (which might be the latest release, but it might not be ... I'm not sure there's any guarantees on for loop iteration order in bash).