Apache AGE Complete Installation Guide - Part 2 ( PostgreSQL )
Tags: age, database, postgres, graphs
Published: 2023-06-11 20:55:51

If you are a Windows user, don't miss Part 1 of this Guide ( WSL tool ) as we will build this blog considering you are using a Linux Terminal.

we start working through this blog from here, 


![Linux terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nzu7gqoy939aqq6ceys.png)



**3. Installing PostgreSQL** 
As we mention before AGE is a PostgreSQL **extension** so we must first have PostgreSQL installed before installing AGE itself.

Important Notes : 
- from age GitHub repo "For now AGE supports Postgres 11, 12 & 13. Supporting the latest versions is on AGE roadmap.", so we can only use it on top of one of those versions ( which means currently not officially compatible with 14, 15, 16 beta) versions on this blog date.

- Mainly the Master branch of the AGE GitHub repository supports PG11 ( PostgreSQL Major version 11 ) 

- If you want to use PG12 you have to switch to the "AGE_PG12.1.0_ALPHA" branch of the age repo ( the master branch is incompatible with PG11 )

- for this tutorial, we will use PG11 ( Major 11, Minor 20, 11.20 Latest minor for this version ) and the source of the master branch in the AGE repo.


let's start,
first of all, we cannot do it like, 
`sudo apt install postgresql` 


![installing latest PG](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qy47crk66dy08d6rtn73.png)


, as this will get the latest version of PostgreSQL according to the current distro information. 
in my case, it gets the PG15, which we cannot use AGE on yet.
 
we need to download a specific version ( for our case here PG11 ), so we specify the version to it as,
`sudo apt install postgresql-11`

for me, this doesn't work from the first try, for a time I was facing the "unable to locate package postgresql-11" error on trying it, and after reviewing the PG documentation I come up with a solution to this error.

to resolve this we do the following commands in order, 
- `sudo apt install curl ca-certificates gnupg`
- `url https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null`
- `sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'`
- `sudo apt update`

After that, we can continue our installation and specify the desired version as we mentioned before and now it works fine with no errors ,


![Specify the version on installing PG](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzjt218b73kaukofafry.png)

but for our case, we need the PG11 one so do it as ,

`sudo apt install postgresql-11` ,

After installation is complete we can check for it using the following command,
`pg_config`


![PG_CONFIG](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyq3zr8569rl2dai7mcz.png)

and to make sure that it's the needed version we check the `VERSION` ,


![PG_CONFIG version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngz2kvat7i0on0g4lvri.png)

then to test it we can use psql ( PostgreSQL interactive terminal ) by,
`sudo -u postgres psql`  



![psql](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c10kekncacba82moj9zd.png)



what's **psql** ?
- psql is a terminal-based front-end to PostgreSQL. 
- It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, the input can be from a file or command line arguments. In addition, psql provides several meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks.


Okay, Now we have done installing the PostgreSQL through the Linux terminal and with the specified version we need, and we are ready for our last step from this tutorial, which is installing AGE and trying it.