Installing Geoserver Binary️ on Ubuntu 18.04 using terminal

Video version of blog

Geoserver is a JAVA-based application developed to ease the styling and sharing of geospatial data using Opensource technology. It follows the standards of the Open Geospatial Consortium (OGC) and thus has wide application in a variety of industries. Geoserver’s website states more clearly regarding its usability and documentation.

Creating fresh EC2 instance

For this blog, we’ll be creating a free-tier amazon ec2 ubuntu instance.

keep the Instance type as t2.micro which is a free tier. In Configure Security Setup add following ports as allowed ports

  1. port 8080 – for geoserver
  2. port 5432 – for postgreSQL

Once the instance is launched, you can create a fresh key pair and download it and use it to login in ubuntu via ssh client such as Terminal for mac, putty for windows, etc.

Go to the downloaded key folder and run the following command

chmod 400 <key_name>.pem

After adding a key, we can log in to Ubuntu machine via ssh using the following command

ssh -i "<key_name>.pem" ubuntu@<ec2_ip>

Let us now begin by understanding the requirements and steps in order to install and run geoserver successfully

Installing Geoserver in a GUI-based system such as Windows, Mac or even Ubuntu GUI is a piece of cake. Have a look at my blogs about windows 👈 or about 👉 mac 👈installations, If you have GUI access for Ubuntu machine you can follow similar steps for mac.

But If you just have a connection to ssh terminal and that’s all. Roll up your sleeves and follow this blog!


First things first, try to use the terminal as an admin user so you don’t have to type password zillion times. Make yourself the owner and go to the root directory :

sudo -u root -i

also, make sure you have an updated system

sudo apt-get update

Step 1: Check/Install JAVA 8

Geoserver currently only supports JAVA-JRE-8, you can install it by typing

sudo apt-get install openjdk-8-jdk
sudo apt-get install openjdk-8-jre

To cross-check installation, type

java -version

and you should get something similar to this as an output

Step 2: Installation of Postgres ( Optional )

Most of the time, we prefer to save the data in the database so that it can be accessible can be used by a lot of other applications as well. Sure Shapefile is better for saving Geospatial data, but it comes with a lot of compromises as well (e.g. not been able to read it/edit without software, etc.). I personally prefer Postgres over other RDBMS, since it is by far the world’s most advanced open-source relational database, and to put the cherry on top of this cake, it also allows us to leverage geospatial capabilities by installing and using PostGIS, PostGIS allows user to query the data using geospatial component ( buffer, within, intersects, etc. )

We’ll start by first installing the latest PostgreSQL version:

sudo apt install postgresql postgresql-contrib

Once the installation is done, you can use PostgreSQL by typing:

sudo su - postgres

and then type psql to open a window like this:

you can get out of PostgreSQL by typing \q and then exit

Now, you can install PostGIS:

sudo apt install postgis

Step 3: Downloading GeoServer

Downloading GeoServer without GUI might get a little tricky since we can’t simply do sudo apt get geoserver (Not at least by the time I’m writing the article  ). But no worries!! If you visit the GeoServer download page, you’ll see that they use Sourceforge to keep their repo, when you click on download, you get redirected and GeoServer starts getting downloaded. If you remove the download from the URL, you’ll get a URL that can be used to download GeoServer zip using terminal

Geoserver Download page (Focus on URL)

now we need a safe place to download and unzip the GeoServer.We’ll create a new directory and put GeoServer in it

cd /usr/share
mkdir geoserver
cd geoserver 
wget https://sourceforge.net/projects/geoserver/files/GeoServer/2.19.0/geoserver-2.19.0-bin.zip

This will download a geoserver-2.18.1-bin.zip file in a GeoServer folder that we just created.The next step is to unzip the geoserver-2.18.1-bin.zip.

sudo apt install unzip
unzip geoserver-2.19.0-bin.zip

This will unzip the GeoServer folder, and if you type ls in the command line, you’ll see something like this:

Finally, we’ll set up a variable to make it workable

echo "export GEOSERVER_HOME=/usr/share/geoserver" >> ~/.profile
. ~/.profile

and make sure that the user is the owner of this folder as well

sudo chown -R USER_NAME /usr/share/geoserver/

Step 4: Once everything is done!

You are there!!

Geoserver is successfully installed and you can now turn it up. head over to bin directory and open startup.sh file

cd bin
sh startup.sh
geoserver started

Then you’ll see stuff beaming up on your terminal, and when you finally see a text something like in the photo, your GeoServer is up and running.

Step 5: Making Geoserver ready for usage!

Since you have installed GeoServer with Terminal, I’m guessing this is for your server, which means we need to be sure that the GeoServer and data inside it is accessible publicly. The default port for GeoServer is 8080, which must be open in your server in order to be able to access GeoServer from anywhere, another business we need to take care of is the CORS policy, Geoserver allows users to get the data as a JSON, XML, etc. hence it is quite important to secure your data. If you try to use GeoServer right now, if you access the layers from another, it’ll show you a CORS error.In order to solve this, you need to uncomment few lines in a web.xml file, which is generally located at

geoserver/webapps/geoserver/WEB-INF

Once you reach in a folder using the terminal, you can open and edit the file using vim. You can install vim by simply typing

sudo apt install vim

and then you can open the web.xml file using vim:

sudo vim web.xml

Vim allows us to modify the file from the terminal. click I (Captial i) to get into insert mode and use arrow keys to move down until you find a line with CORS in Jetty written.

CORS Jetty

Once you find it, Uncomment the code and again search for CORS, Since we are not using tomcat, you can keep CORS related to tomcat commented. You can find the third and final code for CORS.
Once both of these CORS codes are uncommented. You can hit the Esc key to get out of edit mode and type :wq to save the changes in web.xml

Now you can head back to the bin folder again and run the GeoServer

If you get an error while accessing GeoServer, Make sure to head back to the web.xml file and double-check all comments and uncomments.

And we are done!

Leave a Comment

Your email address will not be published. Required fields are marked *