= Installing RNP

Binaries that will be installed:

* `rnp`
* `rnpkeys`


== On NixOS or Nix package manager

We provide a Nix package for easy installation on NixOS and any OS with Nix
installed (including Linux and macOS, even NixOS on WSL).

[source,console]
----
nix-env -iA nixpkgs.rnp
----

== With Nix Flakes

We provide a Nix flake.

[source,console]
----
nix profile install github:rnpgp/rnp
----

== On macOS using Homebrew

We provide a Homebrew tap for easy installation of RNP on macOS.

[source,console]
----
brew tap rnpgp/rnp
brew install rnp
----

== On RHEL and CentOS via YUM

We provide pre-built packages for RHEL and CentOS at our YUM repository hosted
at GitHub.

[source,console]
----
rpm --import https://github.com/riboseinc/yum/raw/master/ribose-packages.pub
rpm --import https://github.com/riboseinc/yum/raw/master/ribose-packages-next.pub
curl -L https://github.com/riboseinc/yum/raw/master/ribose.repo > /etc/yum.repos.d/ribose.repo
yum install -y rnp
----

== On Ubuntu

Prerequisite: please ensure `git` is installed on the system.

[source,console]
----
# Clone the repository by version tag (or omit it to get the latest sources)
git clone https://github.com/rnpgp/rnp.git -b v0.16.3

# Install required packages
sudo apt install g++-8 cmake libbz2-dev zlib1g-dev libjson-c-dev \
  build-essential python-minimal

# Download, build and install Botan2
wget -qO- https://botan.randombit.net/releases/Botan-2.18.2.tar.xz | tar xvJ
cd Botan-2.18.2
./configure.py --prefix=/usr
make
sudo make install
cd ..

# CMake encourages building outside of the source directory.
mkdir rnp-build
cd rnp-build

# Run CMake
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=on \
  -DBUILD_TESTING=off ../rnp/

# Compile
make

# Install
sudo make install
----

== On Debian

Prerequisite: please ensure `git` is installed on the system.

[source,console]
----
# Clone the repository by version tag (or omit it to get the latest sources)
git clone https://github.com/rnpgp/rnp.git -b v0.16.3

# Enable access to `testing` packages by editing /etc/apt/sources.list
# deb http://deb.debian.org/debian testing main

# Install required packages
sudo apt install g++-8 cmake libbz2-dev zlib1g-dev libjson-c-dev \
  libbotan-2-dev build-essential

# Cmake recommend out-of-source builds
mkdir rnp-build
cd rnp-build

# Cmake it
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=on \
  -DBUILD_TESTING=off ../rnp/

# Compile and install
sudo make install
----

== On Gentoo Linux

RNP ebuilds are available from an overlay repository named `rnp`.

=== Using eselect-repository (the current way)

Prerequisite: ensure `eselect-repository` is installed on your system.

[source,console]
----
eselect repository enable rnp
emaint sync -r rnp
emerge -av app-crypt/rnp
----

=== Using layman (the old way)

Prerequisite: ensure `layman` is installed on your system.

[source,console]
----
layman -a rnp
layman -s rnp
emerge -av app-crypt/rnp
----

== Compile from source

Clone this repo, or download a release and expand it.

Enter the source folder and run the following commands:

[source,console]
----
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=on \
  -DBUILD_TESTING=off .

make install
----

== On Windows

=== Using MSYS/MinGW

From a clean MSYS2 install, please first update `pacman` and install required
packages via the `msys` console.

[source,console]
----
pacman -Syu --noconfirm --needed

# Most likely you'll need to close msys console and run it again:
pacman -Syu --noconfirm --needed

# Install packages
pacman --noconfirm -S --needed tar zlib-devel libbz2-devel git automake autoconf libtool automake-wrapper gnupg2 make pkg-config mingw64/mingw-w64-x86_64-cmake mingw64/mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-json-c mingw64/mingw-w64-x86_64-libbotan mingw64/mingw-w64-x86_64-python3
----

Then clone the RNP repository and build it.

[source,console]
----
# CMake encourages building outside of the source directory.
mkdir rnp-build
cd rnp-build

# Add paths to PATH so dependency dll/lib files can be found
export PATH="/c/msys64/mingw64/lib:/c/msys64/mingw64/bin:$PWD/bin:$PATH"

# Run CMake
cmake -DBUILD_SHARED_LIBS=yes -G "MSYS Makefiles" ../rnp

# Compile and install
make && make install
----

=== Using Microsoft Visual Studio 2019

Install `vcpkg` according to
https://docs.microsoft.com/en-us/cpp/build/install-vcpkg?view=msvc-160&tabs=windows[these instructions]:

Set the `VCPKG_ROOT` environment variable to the `vcpkg` root folder.

[source,console]
----
vcpkg install bzip2 zlib botan json-c getopt dirent python3[core,enable-shared]
----

There are two ways to compile and install:

* If you open the MSVC IDE at this folder, it will pick up `CMakeSettings.json`
  to find the `vcpkg` path using the `VCPKG_ROOT` environment variable.

* Otherwise, the following steps will perform a console build for CMake: +
+
--
[source,console]
----
# CMake encourages out-of source builds.
mkdir rnp-build
cd rnp-build
cmake -B . -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake -DCMAKE_BUILD_TYPE=Release ../rnp
cmake --build . --config Release
cmake --install .
----
--

When running `rnp.exe` and `rnpkeys.exe`, please ensure that the following
dependencies are available on path (or inside the same folder as the
executables):

* `librnp.dll`
* `botan.dll`
* `bz2.dll`
* `getopt.dll`
* `json-c.dll`
* `zlib1.dll`

You may check dependencies and their paths via `ntldd.exe` in the MSYS command
prompt.
