How To Build Podman from Source!!

A step-by-step guide to compiling and installing Podman from source on AlmaLinux/Rocky Linux 9

How To Build Podman from Source!!

Recently, I began exploring Podman for various use cases. Podman is a feature-rich container engine and is now the preferred option for Red Hat downstream distributions, as official and community support for Docker on these distros is being phased out.

In this guide, we will walk through a step-by-step process of building Podman from source specifically for Alma/Rocky 9 machines. So, let’s get started!

Step 1: Prepare the Environment

Begin by opening a terminal and executing the following commands:

sudo su -

# Enable EPEL repository
sudo yum install epel-release

# Install build dependencies
wget https://github.com/containers/podman/archive/refs/tags/v5.0.2.tar.gz
tar -xvf v5.0.2.tar.gz
cd podman-5.0.2/
sudo dnf -y builddep rpm/podman.spec - enablerepo=crb

Step 2: Install Python 3.9

We need to install Python as a build dependency. Run the following commands:

sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel

wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
tar -xvf Python-3.9.6.tgz
cd Python-3.9.6/
./configure - enable-optimizations
sudo make
sudo make altinstall
sudo yum install python3-devel python3-setuptools python3-wheel

Step 3: Set up Go (if needed)

If you don’t have Go already installed on your system, execute the following commands:

export GOPATH=~/go
git clone https://go.googlesource.com/go $GOPATH
cd $GOPATH
cd src
./all.bash
export PATH=$GOPATH/bin:$PATH

Step 4: Install Btrfs Dependencies (if needed)

To resolve the dependency error related to btrfs on your Rocky 9 machine, you need to install btrfs and its dependencies. Follow the steps below:

# Install build dependencies
sudo dnf install libuuid-devel libblkid-devel lzo-devel zlib-devel libzstd-devel e2fsprogs-devel e2fsprogs-libs e2fsprogs libgcrypt-devel libsodium-devel libattr-devel
sudo dnf install asciidoc xmlto source-highlight autoconf automake

git clone --depth 1 --branch v5.14.1 https://github.com/kdave/btrfs-progs.git
cd btrfs-progs
git switch -c v5.14.1
export CFLAGS="-O3 -pipe -frecord-gcc-switches -mtune=native -march=native"
export CPPFLAGS=$CFLAGS
export SODIUM_CFLAGS=$CFLAGS
export ZSTD_CFLAGS=$CFLAGS
export ZLIB_CFLAGS=$CFLAGS
export UUID_CFLAGS=$CFLAGS
export PYTHON_CFLAGS=$CFLAGS
./autogen.sh
./configure --with-crypto=libsodium --disable-zoned
make -j12
sudo make install

export PATH="/usr/local/bin:$PATH"

ls -1 /usr/local/bin/ | grep btrfs
btrfs
btrfsck
btrfs-convert
btrfs-find-root
btrfs-image
btrfs-map-logical
btrfs-select-super
btrfstune
fsck.btrfs
mkfs.btrfs

/usr/local/bin/btrfs version  
btrfs-progs v5.14.1

Step 5: Install Build Dependencies & Packages

To install additional packages and build dependencies required by Podman, run the following command:

sudo dnf install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel libuuid-devel libblkid-devel lzo-devel libzstd-devel e2fsprogs-devel e2fsprogs-libs e2fsprogs libgcrypt-devel libsodium-devel libattr-devel asciidoc xmlto source-highlight autoconf automake
sudo dnf install -y catatonit conmon containers-common-extra crun gpgme gpgme-devel device-mapper device-mapper-libs iptables netavark nftables slirp4netns

Step 6: Install Conmon

To install Conmon, execute the following commands:

git clone https://github.com/containers/conmon
cd conmon
export GOCACHE="$(mktemp -d)"
make
sudo make podman

Step 7: Install CRI

To install CRI (Common Runtime Interface), run the following commands:

git clone https://github.com/opencontainers/runc.git $GOPATH/src/github.com/opencontainers/runc
cd $GOPATH/src/github.com/opencontainers/runc
make BUILDTAGS="selinux seccomp"
sudo cp runc /usr/bin/runc

Step 8: Configure CNI

To configure CNI (Container Network Interface), run the following commands:

sudo mkdir -p /etc/containers
sudo curl -L -o /etc/containers/registries.conf https://src.fedoraproject.org/rpms/containers-common/raw/main/f/registries.conf
sudo curl -L -o /etc/containers/policy.json https://src.fedoraproject.org/rpms/containers-common/raw/main/f/default-policy.json

If you experience any issues with the crun version, you can follow these additional steps:

wget https://github.com/containers/crun/releases/download/1.14.4/crun-1.14.4-linux-amd64
mv crun-1.14.4-linux-amd64 crun
chmod +x crun
./crun -v
which crun
sudo cp crun /usr/bin/crun
crun -v

Step 9: Install Podman

Finally, we can install Podman itself. Execute the following commands:

cd podman-5.0.2
make BUILDTAGS="exclude_graphdriver_devicemapper selinux seccomp" PREFIX=/usr
sudo make install PREFIX=/usr

podman --version
podman version 5.0.2

That’s it! You have successfully built Podman from source. You can now start using Podman and taking advantage of its powerful features.


Found something useful? Hold down the 👏 to support and help others find this article. Thanks for reading!!

Follow me on Twitter @akash_Rajvanshi