We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install Glassfish 4.0 on Ubuntu 12.04.3

PostedMarch 17, 2014 101.1k views Java Ubuntu

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.


There are many tutorials available to help you install OpenJDK and JBoss. This is one on the latest concerning Oracle Java and Glassfish. Hopefully this will make deploying easier for Java EE developers.

You will need a droplet with Ubuntu 12.04.3 x64 that has been created with DigitalOcean. Login as root by ssh. This article assumes no Java installed and at least 1G memory, as Java EE servers are quite demanding.

What is Glassfish?

GlassFish is an open-source application server and the reference implementation of Java EE. GlassFish 4.0 release supports the latest Java Platform: Enterprise Edition 7. It supports Enterprise JavaBeans, JPA, JavaServer Faces, JMS, RMI, JavaServer Pages, servlets, etc.

Step One: Install Oracle Java 7

Start by updating the package index:

sudo apt-get update

In order to get Oracle Installer of Java 7, we need to add a new apt repository. In order to use add-apt-repository, you need to install python-software-properties. Here's how to do it by apt-get:

sudo apt-get install python-software-properties

Now you can add the new repository and install from Oracle Installer:

sudo add-apt-repository ppa:webupd8team/java

Make source list up-to-date:

sudo apt-get update

Install Java 7 by apt-get:

sudo apt-get install oracle-java7-installer

After installing, confirm the current Java is Oracle version:

java -version

You will see this:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Step Two: Install Glassfish 4.0

Get Glassfish Zip file

wget download.java.net/glassfish/4.0/release/glassfish-4.0.zip

Install unzip first before unpackage to /opt

apt-get install unzip

Create the directory /opt and then unzip the package to /opt:

unzip glassfish-4.0.zip -d /opt

For convenience, add export PATH=/opt/glassfish4/bin:$PATH to the end of ~/.profile.

Start the glassfish server:

asadmin start-domain

You will see:

Waiting for domain1 to start ...................
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

A domain is a set of one or more GlassFish Server instances managed by one administration server. Default GlassFish Server’s port number: 8080. Default administration server’s port number: 4848. Administration user name: admin; password: none.

In order to visit admin page (yourserverid:4848) remotely, you need to enable secure admin:

asadmin enable-secure-admin

You will see:

Enter admin user name>  admin
Enter admin password for user "admin"> 
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.

Restart domain to make effect of secure admin:

asadmin restart-domain

You will see:

Successfully restarted the domain
Command restart-domain executed successfully.

Now you can visit admin page (yourserverid:4848) in browser

To stop the GlassFish server:

asadmin stop-domain

You will see:

Waiting for the domain to stop .
Command stop-domain executed successfully.

Demo service: deploy hello.war on Glassfish

Download the sample application from Glassfish official samples:

wget https://glassfish.java.net/downloads/quickstart/hello.war

Deploy war file:

asadmin deploy /home/ee/glassfish/sample/hello.war

You will see:

Enter admin user name>  admin
Enter admin password for user "admin"> 
Application deployed with name hello.
Command deploy executed successfully.

Now you can visit yourserverid:8080/hello

To undeploy the application:

asadmin undeploy hello

You will see:

Enter admin user name>  admin
Enter admin password for user "admin"> 
Command undeploy executed successfully.

In order to save typing "admin user name" and "password" every time you deploy or undeploy an application, create a password file pwdfile with content:


Add --passwordfile in command:

asadmin --passwordfile pwdfile deploy /home/ee/glassfish/sample/hello.war

Now the prompt for user name/password won't appear.

Submitted by: Xuan Wu


Creative Commons License