Installing the JDK
Step-by-step guide
- Download the jdk from the Oracle site - google search jdk download
- Extract the tar file to your home
- 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
- Set the following environment variables in your .bash_profile - if you don't set these tomcat will not be able to execute JSP files
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/
- You should be able to type java -version and javac -version
- Navigate back to your home directory, be sure you are logged in as yourself and not root
- Create a file called SmipleTestApplication.java
- Add the following lines of code to it
public class SimpleTestApplication
{
static public void main( String[] args )
{
System.out.println( "Hello world\n");
}
}
- Save the file and exit back to the command line
- Type the following
- javac SimpleTestApplication.java
- Now to run it type
- 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
Related articles