Published January 12, 2018 by

Install Glassfish Server in CentOS/Redhat


Before Installing GlassFish server, you need to install following items on your server:
  • Java/JDK
  • unzip
  • wget
Install unzip and wget

If you are already installed unzip,wget and java so skip this step. Otherwise, you can install it using the following command.

# yum install unzip -y
# yum install wget -y

Install Java in CentOS/Redhat

# cd /opt

# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

# tar xzf jdk-8u161-linux-x64.tar.gz

After extracting java file use alternatives command to install it. alternatives command is available in chkconfig package.

# cd /opt/jdk1.8.0_161/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_161/bin/java 2
# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command


*+ 1           /opt/jdk1.8.0_161/bin/java

Enter to keep the current selection[+], or type selection number: 1

Setup javac and jar commands path using alternatives:

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_161/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_161/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_161/bin/jar
# alternatives --set javac /opt/jdk1.8.0_161/bin/javac

Check Java Version

# java -version

Set Java Environment Variable

Setup JAVA_HOME, JRE_HOME and PATH environment variables

# export JAVA_HOME=/opt/jdk1.8.0_161
# export JRE_HOME=/opt/jdk1.8.0_161/jre

Also insert above environment variables in /etc/environment file.

Install GlassFish Server

Change to the directory where you want to install the GlassFish server


# wget


# unzip
# rm -rf

Start GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin start-domain domain1

Now the glassfish server is started. Glassfish server by default runs on 4848 port. Before login, you need to change the admin password and redirect to secure port.

# /usr/share/glassfish4/bin/asadmin change-admin-password

Here it will ask for admin name, admin password, new admin password, confirm admin password. Remember glassfish default admin password is blank.

# /usr/share/glassfish4/bin/asadmin enable-secure-admin

Here it will ask for admin name, admin password gives this details and restarts glassfish.

Restart GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin restart-domain domain1

Now you can access URL: your_ip_address:4848 and log in with credentials.

After login GlashFish server Console appears.

Stop GlassFish Server

# /usr/share/glassfish4/glassfish/bin/asadmin stop-domain domain1

Channge Admin Password/Forgot Admin Password

To reset the admin password in glassfish replace the file content of domain\config\admin-keyfile with the following:


This will give you a username of 'admin' and password 'changeit'. After changing the file you need to restart the service.