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.
Let us 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-jdksudo apt-get install openjdk-8-jre
To cross-check installation, type
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 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 update sudo apt -y upgrade sudo apt -y install gnupg2 wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list sudo apt update sudo apt install postgis postgresql-13-postgis-3
Once the installation is done, you can test it by creating dummy database and checking if you can use postGIS:
sudo su - postgres
and then type psql to open a window like this:
Create new database
psql -d postgis_db
Once database is created, install postgis extension
CREATE EXTENSION postgis;
If this works, that means PostGIS is Installed.
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
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://build.geoserver.org/geoserver/2.20.x/geoserver-2.20.x-latest-bin.zip apt-get install unzip
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.
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
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
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
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.
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 like
Step 4.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!
In this blog, we succeeded to install JAVA, PostgreSQL, PostGIS, Geoserver using terminal!!