After installing a Java SDK, it is advisable to check that it is ready to use. You can do this by running these two commands, using your normal user account:
$ java -version
$ javac -version
These commands print out the version information for the JRE and JDK (respectively) that are on your shell's command search path. Look for the JDK / JRE version string.
Configuring PATH directly
If there is no java
or javac
on the search path at the moment, then the simple solution is to add it to your search path.
First, find where you installed Java; see Where was Java installed? below if you have doubts.
Next, assuming that bash
is your command shell, use a text editor to add the following lines to the end of either ~/.bash_profile
or ~/.bashrc
(If you use Bash as your shell).
JAVA_HOME=<installation directory>
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export PATH
... replacing <installation directory>
with the pathname for your Java installation directory. Note that the above assumes that the installation directory contains a bin
directory, and the bin
directory contains the java
and javac
commands that you are trying to use.
Next, source the file that you just edited, so that the environment variables for your current shell are updated.
$ source ~/.bash_profile
Next, repeat the java
and javac
version checks. If there are still problems, use which java
and which javac
to verify that you have updates the environment variables correctly.
Finally, logout and login again so that the updated environment variables ptopagate to all of your shells. You should now be done.
Checking Alternatives
If java -version
or javac -version
worked but gave an unexpected version number, you need to check where the commands are coming from. Use which
and ls -l
to find this out as follows:
$ ls -l `which java`
If the output looks like this, :
lrwxrwxrwx. 1 root root 22 Jul 30 22:18 /usr/bin/java -> /etc/alternatives/java
then the alternatives
version switching is being used. You needs to decide whether to continue using it, or simply override it by setting the PATH
directly.
Where was Java installed?
Java can be installed in a variety of places, depending on the installation method.
If you are having difficultly finding the installation directory, We suggest that you use find
(or slocate
) to find the command. For example:
$ find / -name java -type f 2> /dev/null
This gives you the pathnames for all files called java
on your system. (The redirection of standard error to "/dev/null" suppresses messages about files and directories that you can't access.)