Install GlassFish on a CentOS 6 VPS

GlassFishGlassFish is a free open source application server for the Java EE platform. With this application the developers can develop and deploy portable and scalable enterprise Java applications on your Linux VPS.

GlassFish requires a working JDK installation. Skip the first step if you already have it.
1. Install JDK
Create a directory where you want to install JDK:

# mkdir /usr/java

Change to the directory:

# cd /usr/java

Download the latest stable JDK release which currently is JDK 7 update 5 from . Be sure to select the appropriate version to your OS (32 or 64 bit version)

Unpack the downloaded JDK file into the newly created directory:

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

Set the PATH for the JDK installation by editing your ‘~/.bash_profile’ file and adding the following lines:

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

After setting the PATH variable, execute:

# .bash_profile

Or you can simply exit and open the command prompt again.

Check if the PATH is set correctly:

# echo $JAVA_HOME

2. Install the GlassFish Server
Change to the directory where you want to install the GlassFish application:

# cd /opt

Download the latest GlassFish zip installation file:

# wget

Unpack the downloaded zip file:

# unzip

Usually the zip file is extracted to a directory called ‘/glassfish3’

Since it is not recommended to run the glassfish process as root, we need to add group and user for the GlassFish application:

# groupadd glassfish
# useradd -s /bin/bash -g glassfish glassfish
# chown -R glassfish: /opt/glassfish3/

Change the password for the ‘glassfish’ user:

# passwd glassfish
Changing password for user glassfish.
New password:

Create a start/stop/restart script:

# nano /etc/init.d/glassfish
#!/usr/bin/env bash
# description: Glassfish start/stop/restart
# processname: glassfish
# chkconfig: 2445 20 80
export JAVA_HOME
export PATH

case $1 in
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
    su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
exit 0

Save the script and make it executable:

# chmod +x /etc/init.d/glassfish

If you want to start up your GlassFish application on boot execute the following commands:

# chkconfig --add glassfish  
# chkconfig glassfish on

To start/stop/restart Glassfish use the command:

# /etc/init.d/glassfish start/stop/restart

Once the installation is completed, you can open the default GlassFish home page at or the GlassFish admin console at

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

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.

How to install Mailman on a VPS with DirectAdmin
How to install Wekan on Ubuntu 14.04
Install LiteCart on Ubuntu 14.04 with Nginx, PHP-FPM and MySQL
There are currently no comments.