Install GlassFish 4.1 on a Centos 7

install-glassfish-on-a-centos-7-vpsIn this tutorial, we will explain how to install GlassFish Server Open Source Edition 4.1 on a Centos 7.1 VPS. GlassFish is an open-source application server project and it’s Oracle’s concrete implementation of Java EE. This guide should work on other Linux systems as well but was tested and written for a Centos 7.

Login to your System via SSH

ssh root@host

Update the system and install necessary packages

[root]$ yum -y update
[root]$ yum install unzip wget

Create a new system user

Create a new user for the Glassfish server:

[root]$ adduser \
   --comment 'Glassfish User' \
   --home-dir /home/glassfish \

Install Oracle JDK 8

GlassFish 4.1 requires JDK 8 u20 or above. Use the command below to download the Oracle JDK 8 from the command line using wget:

[root]$ wget --no-cookies \
    --no-check-certificate \
    --header "Cookie: oraclelicense=accept-securebackup-cookie" \
    "" \
    -O jdk-8u45-linux-x64.rpm

Once the rpm package is downloaded, install it with:

[root]$ yum install jdk-8u45-linux-x64.rpm

To check if JAVA has been properly installed on your CentOS box run java -version, and the output should be similar to the following:

[root]$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Download and extract the GlassFish 4.1 archive

Switch to the glassfish user:

[root]$ su - glassfish

As the glassfish user, download and extract the latest GlassFish 4.1 archive

[glassfish]$ wget
[glassfish]$ unzip
[glassfish]$ rm -f

Switch back to the root user:

[glassfish]$ exit

Create systemd service

To create a new systemd service for GlassFish, open your editor of choice and create a new file:

[root]$ nano /etc/systemd/system/glassfish.service

and add the following code lines:

Description = GlassFish Server v4.1
After =

ExecStart = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking

WantedBy =

Start the glassfish server and set it to start automatically on boot:

systemctl enable glassfish.service
systemctl start glassfish.service

To verify the unit started, run journalctl -f -u glassfish.service and you should see something like below:

[root]$ journalctl -f -u glassfish.service
Apr 26 17:36:13 vps systemd[1]: Starting GlassFish Server v4.1...
Apr 26 17:36:19 vps java[2767]: Waiting for domain1 to start .....
Apr 26 17:36:19 vps java[2767]: Successfully started the domain : domain1
Apr 26 17:36:19 vps java[2767]: domain  Location: /home/glassfish/glassfish4/glassfish/domains/domain1
Apr 26 17:36:19 vps java[2767]: Log File: /home/glassfish/glassfish4/glassfish/domains/domain1/logs/server.log
Apr 26 17:36:19 vps java[2767]: Admin Port: 4848
Apr 26 17:36:19 vps java[2767]: Command start-domain executed successfully.
Apr 26 17:36:19 vps systemd[1]: Started GlassFish Server v4.1.


The default GlassFish port numbers are:

  • Administration: 4848
  • HTTP listener: 8080
  • HTTPS listener: 8181

For example to open port 8080 in the firewall, run:

firewall-cmd --zone=pubic --add-port=8080/tcp --permanent  
firewall-cmd --reload  

For slower systems

# vi /etc/systemd/system.conf

That’s it. You have successfully installed your GlassFish . For more information about GlassFish , please refer to the Glassfish website.