Installing the JDK

Step-by-step guide

  1. Download the jdk from the Oracle site - google search jdk download
  2. Extract the tar file to your home 
  3. Move the extracted files which should all be within a folder jdk* to /etc - you can move to another location of your choice but be sure to remember where you put it, let's call this <javaHome> and I have used /etc/jdk1.8.0_51
  4. Set the following environment variables in your .bash_profile - if you don't set these tomcat will not be able to execute JSP files
    1. PATH=./:$PATH:$HOME:/<javaHome>/bin

      CLASSPATH=/etc/<javaHome>/jre/lib/rt.jar
      JAVA_HOME=/etc/<javaHome>/
      JDK_HOME=$JAVA_HOME
      JRE_HOME=/etc/<javaHome>/jre/

  5. You should be able to type java -version and javac -version
  6. Navigate back to your home directory, be sure you are logged in as yourself and not root
  7. Create a file called SmipleTestApplication.java
  8. Add the following lines of code to it
    1. public class SimpleTestApplication
      {
            static public void main( String[] args )
            {
                   System.out.println( "Hello world\n");
            }
      }

  9. Save the file and exit back to the command line
  10. Type the following
    1. javac SimpleTestApplication.java
  11. Now to run it type
    1. java SimpleTestApplication

Working with alternative Java installs

If you have multiple JVMs installed you can switch between them using the "alternatives" commands

update-alternatives --install [link] [name] [path] [priority]

So after installing the JDK enter the following command to add it to the alternatives table

shell command
update-alternatives --install "/usr/bin/java" "java" /usr/lib/jvm/java-11-openjdk-amd64/bin/java 2

Now you have to specify which on should be the default version to run for the java command, so use this command

update-alternatives --set [name] [path]

shell command
update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java