How to install Tomcat 7 + JDK 7

Java_logo_and_wordmark.svgThis how-to will show you how to install Tomcat 7.x and JDK 7.x (Java Development Kit) on a CentOS VPS.

You could get one of our Java Hosting plans and have everything already installed and configured but if you want to do it yourself just follow the tutorial below.

1. Install JDK
Choose the correct version for your OS and download the latest JDK release from

Create a new ‘/usr/java’ directory, move the downloaded ‘jdk’ file to ‘/usr/java’ and change to the created directory:

# mkdir /usr/java && mv jdk-7u4-linux-i586.tar.gz /usr/java/ && cd /usr/java/

Unpack jdk-7u4-linux-i586.tar.gz file:

# tar -xzf jdk-7u4-linux-i586.tar.gz

This will create directory, in our case it’s ‘jdk1.7.0_04’

To set the ‘JAVA_HOME’ path add the lines below to your ‘.bash_profile’ file:

export JAVA_HOME=/usr/java/jdk1.7.0_04/
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$PATH:$JAVA_HOME/bin

For the changes to take effect execute:

# source .bash_profile

Check if the ‘JAVA_HOME’ is set correctly:

# echo $JAVA_HOME
# /usr/java/jdk1.7.0_04/

2. Install Tomcat 7

Download the latest Tomcat release (currently 7.0.27) from

# wget

Move the file and change to the ‘/usr/share/’ directory:

# mv apache-tomcat-7.0.27.tar.gz /usr/share/ && cd /usr/share/

Unpack ‘apache-tomcat-7.0.27.tar.gz’ file:

# tar -xzf apache-tomcat-7.0.27.tar.gz

This will create ‘/usr/share/apache-tomcat-7.0.27’ directory. Optionally, you can rename this directory to ‘tomcat7’:

# mv /usr/share/apache-tomcat-7.0.27/ /usr/share/tomcat7

To configure Tomcat 7 to run as a service, change to the ‘/etc/init.d/’:

# cd /etc/init.d/

Using your favorite text editor, create a script called ‘tomcat’ with the following text:

# description: Tomcat Start - Stop - Restart
# processname: tomcat
# chkconfig: 234 20 80
export JAVA_HOME
export PATH

case $1 in
echo "Starting Tomcat"
echo "Stopping Tomcat"
echo "Restarting Tomcat"
echo $"Usage: $0 {start|stop}"
exit 1
exit 0

Make your script executable:

# chmod +x tomcat

Make your Tomcat to start at boot time:

# chkconfig --add tomcat
# chkconfig --level 3 tomcat on

Check if it is setup correctly:

# chkconfig --list tomcat

The default Tomcat port is 8080, so you can try to access it at where you should see Tomcat’s default home page.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

5 thoughts on “How to install Tomcat 7 + JDK 7”

  1. i have follow all the step as mentioned above. But when i access ip-address:8080 the firefox connecting to the address for sometimes and then “Unable to connect” show.
    The output of netstat -an |grep 8080 is:
    tcp 0 0 :::8080 :::* LISTEN

  2. Thanks for sharing such informative article on Java technology. It is most preferred technology among developers to create stunning mobile application fast and easy. It also created massive career opportunity for aspiring professionals.


Leave a Comment

To prove you are human please solve the following *