System Administration

Easy way to install Tomcat server on Ubuntu for JAVA Spring

If you are going to start JAVA Spring development or want to run JAVA spring application on a production server then you must need to prepare the server so it can run your JAVA Spring application. There several articles online but I am writing the easy way so you can just copy and paste the command and get your server ready for JAVA Spring application.

First you have to run the command bellow to update ubuntu package

sudo apt update

Then add repository , Just follow the command bellow

Step 1 – Install Oracle Java 8 on Ubuntu

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Step 2 – Verify Java Installation 

sudo apt-get install oracle-java8-set-default

Check Java Version

java -version

It will show you result like bellow

java version “1.8.0_201″ .
Java(TM) SE Runtime Environment (build 1.8.0_201-b09) .
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

If you still confused you can check this video

<iframe width=”560″ height=”315″ src=”https://www.youtube.com/embed/JQxIFr4zRRs” frameborder=”0″ allow=”accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture” allowfullscreen></iframe>

Step 3 – Create Tomcat User

wget http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.19/bin/apache-tomcat-9.0.19.tar.gz .
tar xzf apache-tomcat-9.0.19.tar.gz .
sudo mv apache-tomcat-9.0.19 /usr/local/apache-tomcat9

Step 4 – Configure Environment Variables

echo "export CATALINA_HOME="/usr/local/apache-tomcat9"" >> ~/.bashrc .
echo "export JAVA_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc . echo "export JRE_HOME="/usr/lib/jvm/java-11-oracle"" >> ~/.bashrc .
source ~/.bashrc

Step 5 – Setup Tomcat User Accounts

Go to tomcat install directory /usr/local/apache-tomcat9 and then edit tomcat-users.xml according to the rule bellow

 <role rolename="manager-gui" />
 <user username="manager" password="_SECRET_PASSWORD_" roles="manager-gui" />

 <!-- user admin can access manager and admin section both -->
 <role rolename="admin-gui" />
 <user username="admin" password="sa123" roles="manager-gui,admin-gui" />

Step 6 – Starting Tomcat Service

cd /usr/local/apache-tomcat9
chmod +x ./bin/startup.sh
./bin/startup.sh

Sample output will be as like bellow

Using CATALINA_BASE:   /usr/local/apache-tomcat9
Using CATALINA_HOME:   /usr/local/apache-tomcat9
Using CATALINA_TMPDIR: /usr/local/apache-tomcat9/temp
Using JRE_HOME:        /usr/lib/jvm/java-11-oracle
Using CLASSPATH:       /usr/local/apache-tomcat9/bin/bootstrap.jar:/usr/local/apache-tomcat9/bin/tomcat-juli.jar
Tomcat started.

If there any problem it may be your JAVA version , which you can resolve by doing the following guideline

go to /usr/local/apache-tomcat9

And then run the following command

JRE_HOME=/usr ./startup.sh

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *