# Installing &repmgr; from source

## Prerequisites for installing from source

To install &repmgr; the prerequisites for compiling &postgres; must be installed. These are described in &postgres;'s documentation on build requirements and build requirements for documentation.

Most mainstream Linux distributions and other UNIX variants provide simple ways to install the prerequisites from packages.

- `Debian` and `Ubuntu`: First add the apt.postgresql.org repository to your `sources.list` if you have not already done so, and ensure the source repository is enabled.

  If not configured, the source repository can be added by including a `deb-src` line as a copy of the existing `deb` line in the repository file, which is usually `/etc/apt/sources.list.d/pgdg.list`, e.g.:

      deb https://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main
      deb-src https://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main

  Then install the prerequisites for building PostgreSQL with e.g.:

             sudo apt-get update
             sudo apt-get build-dep postgresql-9.6

  Select the appropriate PostgreSQL version for your target repmgr version.

  If using `apt-get build-dep` is not possible, the following packages may need to be installed manually:

  - `flex`

  - `libedit-dev`

  - `libkrb5-dev`

  - `libpam0g-dev`

  - `libreadline-dev`

  - `libselinux1-dev`

  - `libssl-dev`

  - `libxml2-dev`

  - `libxslt1-dev`

- `RHEL or CentOS 6.x or 7.x`: install the appropriate repository RPM for your system from yum.postgresql.org. Then install the prerequisites for building PostgreSQL with:

             sudo yum check-update
             sudo yum groupinstall "Development Tools"
             sudo yum install yum-utils openjade docbook-dtds docbook-style-dsssl docbook-style-xsl
             sudo yum-builddep postgresql96

  Select the appropriate PostgreSQL version for your target repmgr version.

  If using `yum-builddep` is not possible, the following packages may need to be installed manually:

  - `flex`

  - `libselinux-devel`

  - `libxml2-devel`

  - `libxslt-devel`

  - `openssl-devel`

  - `pam-devel`

  - `readline-devel`

  If building against PostgreSQL 11 or later configured with the `--with-llvm` option (this is the case with the PGDG-provided packages) you'll also need to install the `llvm-toolset-7-clang` package. This is available via the Software Collections (SCL) Repository.

## Getting &repmgr; source code

There are two ways to get the &repmgr; source code: with git, or by downloading tarballs of released versions.

### Using git to get the &repmgr; sources

Use git if you expect to update often, you want to keep track of development or if you want to contribute changes to &repmgr;. There is no reason not to use git if you're familiar with it.

The source for &repmgr; is maintained at https://github.com/EnterpriseDB/repmgr.

There are also tags for each &repmgr; release, e.g. `v4.4.0`.

Clone the source code using git:

         git clone https://github.com/EnterpriseDB/repmgr

For more information on using git see git-scm.com.

### Downloading release source tarballs

Official release source code is uploaded as tarballs to the &repmgr; website along with a tarball checksum and a matching GnuPG signature. See http://repmgr.org/ for the download information. See appendix-signatures for information on verifying digital signatures.

You will need to download the repmgr source, e.g. `repmgr-4.0.tar.gz`. You may optionally verify the package checksums from the `.md5` files and/or verify the GnuPG signatures per appendix-signatures.

After you unpack the source code archives using `tar xf` the installation process is the same as if you were installing from a git clone.

## Installation of &repmgr; from source

To installing &repmgr; from source, simply execute:

        ./configure && make install

Ensure `pg_config` for the target PostgreSQL version is in `$PATH`.

## Building &repmgr; documentation

The &repmgr; documentation is (like the main PostgreSQL project) written in DocBook XML format. To build it locally as HTML, you'll need to install the required packages as described in the PostgreSQL documentation.

The minimum PostgreSQL version for building the &repmgr; documentation is PostgreSQL 9.5.

In &repmgr; 4.3 and earlier, the documentation can only be built against PostgreSQL 9.6 or earlier.

To build the documentation as HTML, execute:

        ./configure && make doc

The generated HTML files will be placed in the `doc/html` subdirectory of your source tree.

To build the documentation as a single HTML file, after configuring and building the main &repmgr; source as described above, execute:

         ./configure && make doc-repmgr.html

To build the documentation as a PDF file, after configuring and building the main &repmgr; source as described above, execute:

         ./configure && make doc-repmgr-A4.pdf