POSTGRESQL and APACHE AGE installation from source (Linux, Windows and mac)
Published: 2023-02-10 19:03:27

[Apache AGE](https://age.apache.org) is an extension for PostgreSQL that enables users to leverage a graph database on top of the existing relational databases. AGE is an acronym for A Graph Extension and is inspired by Bitnine's [AgensGraph](https://bitnine.net/agensgraph/), a multi-model database fork of PostgreSQL. The basic principle of the project is to create a single storage that handles both the relational and graph data model so that the users can use the standard ANSI SQL along with openCypher, one of the most popular graph query languages today. 

This post will be covering installation of PostgreSQL from source and then installing AGE on top of that.

---


## For Linux Users:

I will be installing PostgreSQL version 11.17 under `~/Desktop/pgsql_11.17/pgsql` directory.

### Pre-requisites:

```bash
sudo apt install gcc build-essential libreadline-dev zlib1g-dev flex bison
```
### PostgreSQL installation:

- Download source code from here or goto terminal and type

```bash
cd ~/Desktop && wget https://ftp.postgresql.org/pub/source/v11.17/postgresql-11.17.tar.gz
```

- Now unzip the file using the command below.

```bash
tar -xf postgresql-11.17.tar.gz && rm postgresql-11.17.tar.gz
```

- Change directory into postgresql-11.17 and configure. This step of the installation procedure is to configure the source tree for your system and choose the options you would like. You can see other configuration options here.

```bash
cd postgresql-11.17 && ./configure --enable-debug --enable-cassert --prefix=$(pwd)/pgsql CFLAGS="-ggdb -Og -fno-omit-frame-pointer"
```

- Type the following command to start the build and installation process.

```bash
make install
```

- Adding pgsql/bin to path so that we can access commands from everywhere.

```bash
echo "export PATH="~/Desktop/postgresql-11.17/pgsql/bin:$PATH"" > ~/.bashrc
```

### PostgreSQL Initialization

- Now we have to make a database cluster and own this directory under the current user to start the server.

```bash
mkdir pgsql/data && chown $USER pgsql/data
```

- Now initialize the database cluster.

```bash
initdb pgsql/data
```

- Finally, we are ready to go. Start the server by typing the following command

```bash
pg_ctl -D pgsql/data -l logfile start
```

- Now to stop the server, type

```bash
pg_ctl -D pgsql/data -l logfile stop
```
### AGE Installation:

Now we are ready to install AGE.

- Download the source code from here or clone the repo from GitHub by typing

```bash
cd ~/Desktop && git clone https://github.com/apache/age.git
```

- Now change directory to age and start installation. PG_CONFIG option needs the path to your pg_config command. Since we have already added pgsql/bin in path, so we don’t need to explicitly provide that.

```bash
cd age && make install
```

- Now check the installation by typing. All tests should pass.

```bash
make installcheck
```

TADAAA…. We are ready to use AGE 😎.

### Post installation:

- Change the directory to postgresql-11.17 by typing

```bash
cd ~/Desktop/postgresql-11.17/
```

- Now we will start the server, create a new database and create extension age.

```bash
pg_ctl -D pgsql/data -l logfile start
createdb test
psql test

test=# CREATE EXTENSION age;
CREATE EXTENSION
```


### Per Session Instructions:

```bash
test=# LOAD 'age';
LOAD
test=# SET search_path = ag_catalog, "$user", public;
SET
test=# 
```

We are done with installation and setup phase. For more information about AGE, refer to the [official documentation](https://age.apache.org/age-manual/master/intro/setup.html).

---


## For Windows Users
If you are a windows user, you can follow the steps described in the video below.
{% embed https://www.youtube.com/watch?v=ddk8VX8Hm-I&list=PLGp3huJbWNDjgwP7s99Q-9_w1vxpjNHXG %}

---


## For Mac Users
If you are a mac user, you can follow the steps described in the video below.
{% embed https://www.youtube.com/watch?v=0-qMwpDh0CA %}

---

Follow Apache AGE on following platforms:

{% embed https://github.com/apache/age %}
Twitter : [https://twitter.com/apache_age](https://twitter.com/apache_age)
LinkedIn : [https://www.linkedin.com/showcase/apache-age](https://www.linkedin.com/showcase/apache-age)
Official Website : [https://age.apache.org](https://age.apache.org)