...
- If the server does not already have the directory /opt/java then create one (sudo mkdir /opt/java). change to this directory - cd /opt/java
- Download the version of java appropriate for this version of linux (e.g. x86_64). The version of linux can be determined by running uname -a from the command line.
Oracle requires that you have accepted the license before you download the tar.gz file. This can be problematic for wget. Following is the command to run the download. Go to the Oracle Java download site, click on the accept license button, select the JDK version for this machine and copy the link. Replace the link in the following command with the one you have copied:sudo wget --no-cookies \
--no-check-certificate \0
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz"For Java 8, check "http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" and select the bundle corresponding to "Linux x64", if using linux 64 bits.
- Once the file has completed downloading untar the java distribution and delete the tar file ( sudo tar cxf jdkzxvf jdk-7u55-linux-x64.tar.gz ).
- If the directory, /opt/java, did not exist create a "current" symlink to the new java directory (e.g. sudo ln -s jdk-7u55-linux-x64 current). If the directory, /opt/java, did exist and the link, current, was already there then you will need to sudo unlink current before linking it again. NOTE: The reason for symlinking the directory is so any references to the current java installation (e.g. $JAVA_HOME, /etc/profile.d/java.sh...) do not have to be updated. This simplifies maintenance.
- Remove any previous Java installation from the system. In Centos, get a list of packages:
- rpm -qa | grep openjdk
- sudo rpm -e [package-name]
- At this point, if you do a java -version, you should get: -bash: /usr/bin/java: No such file or directory
- Add export
System Configuration:
The following instructions configure various server components to work in conjunction with the Tomcat server and Java. Below you will find instructions on best practice for installing init.d script for Tomcat and how to create both $CATALINA_HOME and $JAVA_HOME for all users.
...
- If an entry for java.sh does not already exist in /etc/profile.d/java.sh then you will need to create one; sudo vi /etc/profile.d/java.sh
In this file put the following line:
- If an entry for java.sh does not already exist in /etc/profile.d/java.sh then you will need to create one; sudo vi /etc/profile.d/java.sh
export JAVA_HOME=/opt/java/current
export PATH=$JAVA_HOME/bin:$PATH
If the file already exists be sure it has the above entry.
- Once you open a new shell or login you will be able to test this configuration:
echo $JAVA_HOME should return /opt/java/<the directory you installed> - and running java -version should return the version of Java you have installed.
- Once you open a new shell or login you will be able to test this configuration:
...