A beginner friendly guide on Installing Apache AGE and PostgreSQL from source on WSL
Tags: apacheage, postgres, wsl, beginners
Published: 2023-02-26 11:51:46

## Introduction
Graph databases are gaining popularity due to their inherent design of storing and managing data using graph structures and being able to model and query complex relationships intuitively. There are several graph database technologies available in the market, and one of the technologies we will see today is Apache AGE. 
PostgreSQL is one of the most popular and powerful open-source Relational Database Management Systems (RDMS), built upon it is an extension of Apache AGE which is an open-source project that supports the property graph model and provides a native graph storage and processing engine for managing large-scale graph data. Today we will see a step-by-step guide on installing and setting up Apache AGE and PostgreSQL. 

## Prerequisite before Installation
Before starting the installation you should have WSL enabled and installed on your system. If you don't have WSL installed you can consider the [official docs here](https://learn.microsoft.com/en-us/windows/wsl/install) or you can also take help from this [blog](omgubuntu.co.uk/how-to-install-wsl2-on-windows-10). After installing WSL you should also have git installed and if not take help from [here] (https://github.com/git-guides/install-git#install-git-on-linux) and follow the guidelines of installing on Linux.

I have used ubuntu on WSL and below are the steps for installing Apache AGE and PostgreSQL from the source.

## Installation:
First lets make a new directory so as to making up the installation clean.

```
mkdir apache
cd apache
```
We also need some important libraries which can be downloaded by using the below command.

```
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison
```

### 1. Installing Postgres from Source:
For installing Postgres you need to install a compatible version of Postgres and currently AGE supports only Postgres version 11 and 12.

Here I am using version 11.18.

To install postgresql:

- Download the postgresql using the following command:
 
```
wget https://ftp.postgresql.org/pub/source/v11.18/postgresql-11.18.tar.gz && tar -xvf postgresql-11.18.tar.gz && rm -f postgresql-11.18.tar.gz
 ```
The above command would download and extract the postgresql-11.18.
You would see the following output:
![Download output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq21c56faamuj0llz255.png)

- Configuring and installing postgresql using the following commands:

```
cd postgresql-11.18

# configuring
./configure --prefix=$(pwd) --enable-debug --enable-cassert CFLAGS="-ggdb -Og -fno-omit-frame-pointer"

# installing
make install

# moving back to apache folder
cd ..
```
This would take a while to complete and after completion you would see the following output after the make install command:

![Install complete output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbzvrhzrzco2pql2zpuo.png)

> NOTE: If the make install command gives you error, try `sudo make install` as sometimes the home directory in windows is a protected folder and you need admin permissions to add files to it.

> Also in the above command the prefix flag contains the path where PSQL would install you can either replace the path to your custom or this would install in the `postgresql-11.18` directory.

### 2. Installing Apache AGE:
Follow the following commands to install and setup AGE.

```
git clone https://github.com/apache/age.git

# configuring AGE with PostgreSQL.
sudo make PG_CONFIG=/home/aditya/apache/postgresql-11.18/bin/pg_config install

# checking if everything is alright
make PG_CONFIG=/home/aditya/Apache/postgresql-11.18/bin/pg_config installcheck
```

> In the above command PG_CONFIG would point to the `pg_config` file which is stored in the `bin` folder. Also the `installcheck` command would check if the installation has been successful.

After the above commands you would see the following output:

![Tests Passed output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0i7i10902c8l4mx8ofk.png)

## References:
You can check the following for more info on installation and setup:
1. [Ubuntu Installation - Stackoverflow](https://stackoverflow.com/questions/75096701/how-to-install-age-extension-of-postgresql-from-source-code-in-ubuntu/75116011#75116011)
2. [Apache AGE Setup](https://age.apache.org/age-manual/master/intro/setup.html)
3. [PostgreSQL Installation](https://www.postgresql.org/docs/current/install-procedure.html)

### Installation on other OS:
For installation on other operating systems you can check out the following blogs:
1. [MacOS](https://dev.to/xk_woon/how-to-install-postgresql-and-apache-age-on-macos-45m8)
2. [Windows](https://dev.to/carlasanches/easy-guide-to-install-and-configure-postgresql-with-apache-age-on-windows-n6p) (This covers a different approach which you can use).
3. [Linux](https://dev.to/talhahahae/installation-of-apache-age-and-postgresql-from-source-in-linux-part-1-gka) - Although the steps for Linux might be same this blog also has a [part-2](https://dev.to/talhahahae/initialization-and-creating-a-database-for-testing-the-installation-of-postgres-and-age-part-2-118l) which contains instruction for testing.

### Video tutorials
You can also check the following video tutorials:
3. [Windows](https://youtu.be/ddk8VX8Hm-I)
4. [MacOS](https://youtu.be/0-qMwpDh0CA)

For a detailed tutorial you can check out [this](https://theundersurfers.netlify.app/age-installation) blog too!

You can also visit [Apache AGE Github](https://github.com/apache/age) repository to start contributing or can visit their [website](https://age.apache.org/) for more info.

That's it for today guys. I hope this would help you in getting started with Apache AGE.