How To Set up GlassFish on Ubuntu 20.04

In this article, we want to teach you How To Set up GlassFish on Ubuntu 20.04.

GlassFish is a free, open-source software application server and developed by Sun Microsystems (now Oracle). It implements technologies defined in the Java EE platform of this company and allows running apps that support this specification.

Set up GlassFish on Ubuntu 20.04

Before you start to install GLassFish on Ubuntu 20.04, you need to log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our article the Initial Server Setup with Ubuntu 20.04.

Now follow the steps below to install GlassFish on Ubuntu 20.04.

Install Java on Ubuntu 20.04

To install GlassFish on Ubuntu 20.04 you need to have Java installed on your server. First, update your local package index with the following command:

sudo apt update

Then, use the following command to install OpenJDK 8 on Ubuntu 20.04:

sudo apt install openjdk-8-jdk

Verify your Java installation by checking its version:

java -version

In your output you will see:

openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~20.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

Install GlassFish on Ubuntu 20.04

At this point, you need to download the latest version of GlassFish from the GlassFish Downloads Page.

First, switch to the /opt directory with the command below:

cd /opt

Then, use the following command to download the GlassFish on Ubuntu 20.04:

sudo wget

When your download is completed, extract your downloaded file with the command below:

sudo unzip

Now you need to create a systemd unit file for the GlassFish service. Create and open the file with your favorite text editor, here we use vi:

sudo vi /etc/systemd/system/glassfish.service

Add the following contents to the file:

Description = GlassFish Server v5.0
After = [Service]
ExecStart=/opt/glassfish5/bin/asadmin start-domain
ExecReload=/opt/glassfish5/bin/asadmin restart-domain
ExecStop=/opt/glassfish5/bin/asadmin stop-domain
Type = forking [Install]
WantedBy =

When you are done, save and close the file.

Next, you need to reload the system services with the following command:

sudo systemctl daemon-reload

Now you can start and enable GlassFish to start on boot with the commands below:

sudo systemctl start glassfish
sudo systemctl enable glassfish

Verify that your GlassFish service is active and running on Ubuntu 20.04 with the following command:

sudo systemctl status glassfish

In your output you will see:

glassfish.service - GlassFish Server v5.0
     Loaded: loaded (/etc/systemd/system/glassfish.service; enabled; vendor pre>
     Active: active (running) since Tue 2021-12-21 12:52:53 CET; 1min 15s ago
   Main PID: 5476 (java)
      Tasks: 78 (limit: 2282)
     Memory: 363.6M
     CGroup: /system.slice/glassfish.service
             └─5476 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -cp /opt/glassfi>

Configure GlassFish on Ubuntu 20.04

The default GlassFish admin password is blank. For more security, you can set a password for your GlassFish admin user.

GlassFish has a tool called asadmin that accepts commands for setting up GlassFish via a command line.

To make this command executable anywhere, run the following command:

export PATH=/opt/glassfish5/bin:$PATH

Now you can use the following command to set a GlassFish admin password:

asadmin --port 4848 change-admin-password

You will be asked to enter the admin password, press enter to set a new password.

Enter admin user name [default: admin]>admin
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>

In your output you will see:

Command change-admin-password executed successfully.

Next, you need to enable the secure admin feature with the following command:

asadmin --port 4848 enable-secure-admin

You should enter your admin username and password then, in your output you will see:

Command enable-secure-admin executed successfully.

Now restart GlassFish on Ubuntu 20.04 to apply the changes:

sudo systemctl restart glassfish

Access GlassFish Web Interface

At this point, you can access the default GlassFish page by typing your server’s IP address in your web browser followed by 8080:


You will see:

GlassFish web interface on Ubuntu 20.04

Also, you can access the web administrator console by typing your Server’s IP address in your web browser followed by 4848:


You will see the GlassFish Administration console login screen.

Enter your GlassFish admin user and password, you will see:

GlassFish Admin interface


At this point, you learn to set up GlassFish on Ubuntu 20.04.

Hope you enjoy using it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!