A thing that always annoys me about installing Java is that it doesn't automatically set up the JAVA_HOME environment variable after installation. I guess this is to avoid having problems when you have multiple virtual machines installed. Anyway, I use Ubuntu Linux to host the majority of my Java Application Server. It is easy install Java (sudo apt-get install sun-java6-jdk
) but there always seems to be a debate about where to set the JAVA_HOME
environment variable. Some instructions say you should add it to your personal profile (e.g. ~/.bashrc
) others suggest adding it to the global profile (i.e. /etc/profile
), some people even suggest adding it directly in the init script for the services that need the variable. My suggest is to add an executable shell script to /etc/profile.d/
called javahome.sh
. The content of the file would be: export JAVA_HOME=/usr/lib/jvm/java-6-sun
. All shell scripts (i.e. executable files with the extension .sh
) located in the /etc/profile.d/
directory are loaded upon login and would therefore work for all users without having to change system files that may change upon the next O/S upgrade. To test the script simply type source /etc/profile
This will reload the profile for the current user. To verify that the environment variable has been initialised type export|grep JAVA_HOME
Enjoy!
Wednesday, 31 December 2008
Setting JAVA_HOME on Ubuntu
Subscribe to:
Posts (Atom)