Installation of Java is really quite easy, if you have done it a few times. However there are a number of considerations that make it impossible for me to provide explicit installation instructions that will work in all situations.
These questions are occasionally crucial to successful installation of Java. However much of the time the above questions will be irrelevant, or else you will be able to answer them with certainty. In particular, if your computer is self-managed, and doesn't yet have Java installed, then installation will be easy. In that case, go ahead with the installation of Java, making use of my notes below and adapting them where necessary to your situation and goals. But otherwise prudence should rule:
|
The following assumes you have 'root' privileges, don't have any pre-existing version of Java to deal with, and are doing an installation in the program area that is common to all users of your computer.
The two main installation alternatives are to use the version direct from Sun, or the repackaged version from your Linux version (CentOS, Debian etc). Both are acceptatable.
Anyone intending to do Java programming should also download and install (a) the documentation for Java, and (b) Ant. The latter is a utility that is helpful for compiling Java. However if you are simply running Jeda (or the Jeda demo) as is, then these are not necessary, or can be added later.
Ant is available as a .zip, .tar.gz or .tar.bz2 archive file. Choose whichever you are most familiar with.
The general plan is to install Java in a place that is common to all users, but doesn't interfere with any of the directories used by the package manager. This minimizes the chance of interference between Java and anything else on your system. I recommend installing everything (Java, the documentation, Ant) under a new directory /usr/java. This directory can then hold all these aspects of Java, plus new versions or each.
You need administrator privileges to perform the installation. So within a terminal window you will need to become root, one way or another: in RedHat-like systems you type su - followed by the root password; in Debian-like systems you type sudo -i followed by your own password (assuming you are a sudoer).
mkdir /usr/java # or whatever you like
cd /usr/java
# Move JDK to this directory and unpack
mv <wherever>/jdk-6u16-linux-x64.bin .
chmod +x jdk-6u16-linux-x64.bin
./jdk-6u16-linux-x64.bin
# Scroll to the end of the license agreement and answer 'yes'
# Watch the unpacking complete
rm jdk-6u16-linux-x64.bin # tidy up
# Optional: Unpack documentation
mv <wherever>/jdk-6-doc.zip .
unzip jdk-6-doc.zip
rm jdk-6-doc.zip
# Optional: Unpack Ant (.tar.gz version)
mv <wherever>/apache-ant-1.7.1-bin.tar.gz .
tar xvf apache-ant-1.7.1-bin.tar.gz
rm apache-ant-1.7.1-bin.tar.gz
# Result will be that /usr/java now has three subdirectories:
# /usr/java/jdk1.6.0_16
# /usr/java/docs
# /usr/java/apache-ant-1.7.1
The above installation also provides the Java browser plugin. This plugin enables running of Java applets, which are sometimes embedded in web pages, e.g. my FFT Demo. (Note that Java and JavaScript are totally independent languages; so the present discussion has no impact on normal browser operation.) If you wish to link your browser to your new version of Java, then there a couple of intricate steps. My own experience is just with Firefox and Unbuntu, so you will probably need to adapt the following to your environment. [The organization of plugins appears to be in flux.]
# On x86-32 systems
cd /usr/lib/firefox/plugins # or else /usr/lib/xulrunner-addons/plugins/
rm libjavaplugin_oji.so # if present
ln -s /usr/java/jdk1.6.0_16/jre/plugin/i386/ns7/libjavaplugin_oji.so
# On x86-64 systems, $JAVA_HOME/jre/lib/amd64/libjavaplugin_jni.so
# exists, but doesn't do anything when linked to in the normal way.
# However the following does work.
cd /usr/lib/firefox/plugins # or else /usr/lib/xulrunner-addons/plugins/
rm libnpjp2.so # if present
ln -s /usr/java/jdk1.6.0_16/jre/lib/amd64/libnpjp2.so
Restart Firefox, enter the pseudo-URL about:plugins, and the browser will show whether the new version of Java has been found.
After installing Java, the final step is to add (or modify) your environment variables. These are a number of labelled values that are commonly used for system configuration. In the present context they are used to help the operating system find where Java was installed, and to help programs like Jeda to locate certain resources.
Linux users can simply edit their startup scripts. The goal is to set three new environment variables, and append to your PATH:
| Variable | Example value |
|---|---|
| JAVA_HOME | /usr/java/jdk1.6.0_16 |
| JAVA_BINDIR | /usr/java/jdk1.6.0_16/bin |
| ANT_HOME | /usr/java/apache-ant-1.7.1 |
| PATH | $PATH:$JAVA_HOME/bin:$ANT_HOME/bin |
The lines to add to your startup script depend on what shell you use. For the Bash shell, I use the following:
# Java
export JAVA_HOME=/usr/java/jdk1.6.0_16
export JAVA_BINDIR=${JAVA_HOME}/bin
echo $PATH | /bin/grep -q -v $JAVA_BINDIR
if [ $? -eq 0 ]; then export PATH="${PATH}:$JAVA_BINDIR"; fi
# Ant
export ANT_HOME=/usr/java/apache-ant-1.7.1
echo $PATH | /bin/grep -q -v $ANT_HOME/bin
if [ $? -eq 0 ]; then export PATH="${PATH}:$ANT_HOME/bin"; fi
The C Shell uses the syntax setenv var value instead of export var=value. Also the 'if' syntax is slightly different.
Changes to variables do not take effect until you open a new terminal.
To confirm that the PATH change was successful, open a terminal (and it shouldn't matter which folder you are in), and type the following:
java -version # version should be >= 1.5 javac -version # version should be >= 1.5 ant -version # version should be >= 1.7 [optional]
Sun provides an RPM version of the JDK, with a name like jdk-6u16-linux-i586-rpm.bin. This may work in your environment. However it is hard to believe that it is 100% compatible with your particular package management system. Best avoided.
Under RedHat, Fedora, SuSE and related distributions there are various package management utilities, of which rpm is the most fundamental, but yum is probably more common these days. If using yum, type
su -c "yum install java-1.6.0-openjdk" # I don't know about Sun's Java
This section need expanding ...
Under Debian, Ubuntu and related distributions there are various package management utilities, of which apt-get is the most fundamental. A full installation involves several packages. If using apt-get, then see what is available (apt-cache search 'sun-java') and type something like:
sudo apt-get install sun-java6-bin
sudo apt-get install sun-java6-doc
sudo apt-get install sun-java6-fonts
sudo apt-get install sun-java6-javadb # optional
sudo apt-get install sun-java6-jdk
sudo apt-get install sun-java6-jre
sudo apt-get install sun-java6-plugin
sudo apt-get install ant # optional
sudo apt-get install ant-doc # optional
sudo apt-get install ant-optional # optional
Some Ant scripts look for the environment variable JAVA_HOME, so add JAVA_HOME="/usr/lib/jvm/java-6-sun" to the list of standard environment variables, /etc/environment. There are some relevant comments in /usr/share/doc/sun-java6-jre/.
Your distribution may implement a system allowing for multiple versions of packages: update-alternatives and JPackage are ones I have heard of. In the former case type update-alternatives --display group to see what is available, and update-alternatives --config group to switch between versions. The two relevant values for group are java and javac. (There is a front-end to this utility, update-java-alternatives.)
Finally, to confirm that the installation was successful, open a new terminal, and type the following:
java -version # version should be >= 1.5 javac -version # version should be >= 1.5 ant -version # version should be >= 1.7
If the version numbers are reported, and are sufficiently recent, then Java has been installed successfully. Proceed now with installing Jeda.
| Validate HTML CSS | Last changed 2009-09-23 | Chris Rennie |