X

How To Install Java And Tomcat On Ubuntu 16.04

Now I want to share how to install java and tomcat on your ubuntu 16.04 server. This tutorial is manual installation process for installation java and tomcat. You can install java and tomcat any directory, if you use my guide. So let’s start for installation process.

How To Install WordPress On Ubuntu 20.04
How To Install DNS Server (Bind9) On Ubuntu 20.04

My server info :
Server IP : 10.66.50.10
Disk : 25 GB
RAM : 2 GB
vCPU : 2
Service : Java & Tomcat
Web : Tomcat
vJava : jdk-8u191
vTomcat : 8.0.53

Download Java from jdk-8u191  and download Tomcat 8.0.53. Must be account needed for java package download. After complete download and connect your server via ssh then upload this file.

Step #01: Server update and extract Java and Tomcat file.

root@Ubuntu-16:~# apt update && apt-get upgrade
root@Ubuntu-16:~# apt install unzip
root@Ubuntu-16:~# mkdir -p /home/app/Java/jdk/
root@Ubuntu-16:~# mkdir -p /home/app/Tomcat
root@Ubuntu-16:~# tar xf jdk-8u191-linux-x64.tar.gz
root@Ubuntu-16:~# unzip apache-tomcat-8.0.53.zip
root@Ubuntu-16:~# mv jdk1.8.0_191/ /home/app/Java/jdk/8.0.191
root@Ubuntu-16:~# mv apache-tomcat-8.0.53 /home/app/Tomcat/8.0.53

Create setenv.sh file for environment variable.

root@Ubuntu-16:~# vi /home/app/Tomcat/8.0.53/bin/setenv.sh

Insert below all text into setenv.sh file and save.

export JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms1024m -Xmx2048m -XX:PermSize=64m -XX:MaxPermSize=256m"

For save press Esc type :wq press Enter.

Then run below command for select update file location.

root@Ubuntu-16:~# update-alternatives --install "/usr/bin/javac" "javac" "/home/app/Java/jdk/8.0.191/bin/javac" 1
root@Ubuntu-16:~# update-alternatives --install "/usr/bin/java" "java" "/home/app/Java/jdk/8.0.191/bin/java" 1
root@Ubuntu-16:~# update-alternatives --set "javac" "/home/app/Java/jdk/8.0.191/bin/javac"
root@Ubuntu-16:~# update-alternatives --set "java" "/home/app/Java/jdk/8.0.191/bin/java"
root@Ubuntu-16:~# chmod -R 755 /home/app/

Step #02: Open profile file and add java file location.

root@Ubuntu-16:~# vim /etc/profile

Insert below text into profile file.

JRE_HOME=/home/app/Java/jdk/8.0.191
PATH=$PATH:$JRE_HOME/bin
export JRE_HOME
export PATH

For save press Esc type :wq then press Enter.

Step #03: Setup tomcat heap memory.

root@Ubuntu-16:~# vim /home/app/Tomcat/8.0.53/bin/catalina.sh

Insert below text into catalina.sh file.

#tomcat heap memory set
JAVA_OPTS="-Dfile.encoding=UTF-8 -server -Xms1024m -Xmx2048m -XX:PermSize=64m -XX:MaxPermSize=256m -Djava.awt.headless=true -XX:+UseParallelGC -XX:MaxGCPauseMillis=100"

Then save file using press Esc type :wq then press Enter.

Step #04: Create tomcat start and stop file.

root@Ubuntu-16:~# vim /etc/init.d/tomcat

Then insert below all text into tomcat file.

#!/bin/bash
### BEGIN INIT INFO
# Provides:tomcat8
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO

JAVA_HOME=/home/app/Java/jdk/8.0.191
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/home/app/Tomcat/8.0.53
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0

For save press Esc type :wq then press Enter.

Step #05: Setup permission for tomcat file.

root@Ubuntu-16:~# chmod 755 /etc/init.d/tomcat
root@Ubuntu-16:~# /etc/init.d/tomcat start

all is done! now browse your server ip address using 8080 port.

http://10.66.50.10:8080

If any problem please see my YouTube channel for more details. Please subscribe my channel for more update.

0 0 votes
Article Rating
Admin: I am system administrator as Windows and Linux platform. I have 4 years skilled from the professional period. I have to configure Linux based system such as an Asterisk VOIP system, Network monitoring tools (ZABBIX), Virtualization (XEN Server), Cloud computing (Apache CloudStack) etc. Now share my professional skill each interested person. Thanks to all.
Leave a Comment