Install Geoserver on Ubuntu Server

Install Geoserver on Ubuntu Server

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

No alt text provided for this image


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 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 -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        

and then type psql to open a window like this:

No alt text provided for this image


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 build page, https://build.geoserver.org/geoserver/ you can select the interested geoserver version. For now, we'll use main which is latest stable version.

We’ll create a new directory and put GeoServer in it

cd /usr/share
mkdir geoserver
cd geoserver

wget https://build.geoserver.org/geoserver/main/geoserver-main-latest-bin.zip        

This will download a geoserver-main-latest-bin.zip file in a GeoServer folder that we just created.

The next step is to unzip the geoserver-main-latest-bin.zip.

unzip geoserver-main-latest-bin.zip        

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

No alt text provided for this image


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        
No alt text provided for this image


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.

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!!
Sajiya Salat

DevOps Engineer | AWS Community Builder | Entrepreneur | Application Services

10mo

hello Krishna Lodha why didnt you use microservice approach for setting up geoserver?

Like
Reply

Thanks for Sharing.

Shai Sussman

🌍 Geo-Data Scientist 💻 Python Dev📍Location-Based Solutions

2y

it seems like in version 2.23 openjdk-8-jdk, is not sufficent, and default-jre satisfies the requirement.

Karim C.

Linux System Administrator

2y

This is not production development which will serve under any domain?

Jordan Bess

Solutions Architect and Developer (expert in Geospatial Data)

2y

Thanks - users that can work with Rasters that are cached as map tiles (MBTILES or GPKG) already can check out our powerful and flexible solutions https://portfolio.techmaven.net/apps/geospatial-servers-on-premise-or-at-edge/ That can run on a laptop at the edge or on a production web server. Includes build in advanced map viewers/editors and ability to make self service portal. https://www.youtube.com/watch?v=asK7xRfb7YQ&t=10sl

To view or add a comment, sign in

Others also viewed

Explore topics