Kapitan is an open-source tool from Kapicorp for templated configuration management. It builds Kubernetes manifests, Terraform files, scripts and documentation from one inventory, and it can handle secrets. This page shows how to install it on Ubuntu with pip or Docker. The notes below update those commands for current Ubuntu releases and walk you through compiling your first target to check that the install works.
Install Kapitan in Ubuntu
$ sudo apt-get update && sudo apt-get install -y python3.8-dev python3-pip python3-yaml
$ pip3 install --user --upgrade kapitan
# kapitan will be installed in $HOME/.local/lib/python3.7/bin
#not recommended
$ sudo pip3 install --upgrade kapitanCode language: PHP (php)
Install Kapitan using Docker Container
# Linux
$ alias kapitan="docker run -t --rm -u $(id -u) -v $(pwd):/src:delegated kapicorp/kapitan"
$ kapitan -h
# Mac
$ alias kapitan="docker run -t --rm -v $(pwd):/src:delegated kapicorp/kapitan"
$ kapitan -h
Code language: PHP (php)
Create Kapitan Project from Scratch
If you want to start off with a clean kapitan project, you can run kapitan init --directory <directory> to populate a new directory with the recommended kapitan folder structure.
The bare minimum structure that makes use of kapitan features may look as follows:
$ kapitan init –directory <directory>

Choosing an installation method
Kapitan is a Python application that is published on PyPI and as the kapicorp/kapitan container image. All the methods give you the same CLI. They differ in how they handle Python versions and where the files go.
| Method | Best for | Notes |
|---|---|---|
| Python virtual environment | Workstations and CI runners with Python 3 | Keeps Kapitan's dependencies away from the system Python. Works on Ubuntu 23.04 and later. |
| pipx | One global kapitan command per user | pipx creates and manages the virtual environment for you. |
| Docker image | Machines without a suitable Python, or teams that need identical versions | Needs Docker. Files are reached through a bind mount. |
pip3 install --user | Older distributions only | Blocked by default on recent Ubuntu (PEP 668). |
Note: Recent Kapitan releases need a modern Python 3. If pip only finds an old Kapitan version, or refuses to install it, your Python is probably too old. The PyPI page lists the supported Python versions for each release.
Corrected Ubuntu installation using a virtual environment
The apt command above installs python3.8-dev. That package exists only on older releases such as Ubuntu 20.04. On 22.04 and 24.04, apt reports that it has no installation candidate. Install the generic packages instead, and put Kapitan in a virtual environment:
sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip python3-dev build-essential
# Create an isolated environment for Kapitan
python3 -m venv ~/.venvs/kapitan
source ~/.venvs/kapitan/bin/activate
pip install --upgrade pip
pip install --upgrade kapitan
kapitan --versionCode language: JavaScript (javascript)
python3-dev and build-essential are only needed when a dependency has no prebuilt wheel for your platform and pip has to compile it. Installing them up front prevents confusing build failures. You do not need python3-yaml, because pip installs PyYAML as a Kapitan dependency.
To run kapitan without activating the environment each time, link the binary into a directory on your PATH:
mkdir -p ~/.local/bin
ln -sf ~/.venvs/kapitan/bin/kapitan ~/.local/bin/kapitan
# Add ~/.local/bin to PATH if it is not already there
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
which kapitanCode language: PHP (php)
Note: With pip3 install --user, the kapitan executable goes in ~/.local/bin, not $HOME/.local/lib/python3.7/bin as the comment above says. The library files go under ~/.local/lib/python3.X/site-packages.
Installing with pipx
pipx installs each Python CLI in its own virtual environment and exposes the command in ~/.local/bin. This gives you the same isolation as the manual method with fewer steps:
sudo apt-get install -y pipx
pipx ensurepath # adds ~/.local/bin to PATH; open a new shell afterwards
pipx install kapitan
kapitan --version
# Later upgrades
pipx upgrade kapitanCode language: PHP (php)
Running Kapitan with Docker
The Docker aliases above work. In both, --rm removes the container after each run, and -v $(pwd):/src mounts the current project into the container's working directory. On Linux, -u $(id -u) makes sure that files written to compiled/ are owned by you and not by root. The :delegated mount flag only ever mattered on Docker Desktop for Mac and can be left out.
A shell function passes arguments more reliably than an alias, and a pinned image tag keeps results the same across machines:
# Add to ~/.bashrc or ~/.zshrc
kapitan() {
docker run -t --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd)":/src \
kapicorp/kapitan "$@"
}
kapitan --versionCode language: PHP (php)
- Replace
kapicorp/kapitanwith a specific release tag from Docker Hub, so that every engineer and CI job compiles with the same version. - Run the function from the project root. The container only sees the directory you mount, so files outside it, such as
../shared, are not available. - If you use GPG-backed secrets, also mount your keyring into the container at the path your image expects, or run Kapitan natively instead.
Verifying the install with a first target
kapitan init --directory <directory> creates the recommended layout: inventory/ for classes and targets, plus folders for components and templates. You can also write a minimal project by hand, which shows how the parts connect:
mkdir -p demo/inventory/targets demo/templates && cd demo
cat > inventory/targets/dev.yml <<'EOF'
parameters:
app:
name: demo-app
replicas: 2
kapitan:
vars:
target: dev
compile:
- output_path: manifests
input_type: jinja2
input_paths:
- templates/configmap.yml
EOF
cat > templates/configmap.yml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ inventory.parameters.app.name }}
data:
replicas: "{{ inventory.parameters.app.replicas }}"
EOF
kapitan compileCode language: JavaScript (javascript)
Kapitan reads every file in inventory/targets/, renders the inputs listed under parameters.kapitan.compile and writes the results to compiled/<target>/. Here the rendered file is compiled/dev/manifests/configmap.yml, with demo-app and "2" filled in. Some other useful commands:
kapitan inventory -t dev # show the merged inventory for one target
kapitan compile -t dev # compile a single target
kapitan searchvar parameters.app.name # find where a variable is definedCode language: PHP (php)
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
error: externally-managed-environment | Ubuntu 23.04+ blocks pip from writing to the system or user site-packages (PEP 668). | Use a virtual environment or pipx. Avoid --break-system-packages. |
Package python3.8-dev has no installation candidate | That versioned package is not in your Ubuntu release. | Install python3-dev instead. |
kapitan: command not found | ~/.local/bin or the venv's bin is not on PATH. | Activate the venv, run pipx ensurepath, or update PATH and open a new shell. |
Permission denied writing compiled/ (Docker) | The container ran as root earlier and created root-owned files. | Run sudo chown -R $USER: compiled and always pass -u $(id -u). |
permission denied ... docker.sock | Your user cannot reach the Docker daemon. | Add the user to the docker group (sudo usermod -aG docker $USER), then log in again. |
| Target not found or empty output | You ran Kapitan outside the project root, or input_paths is wrong. | Run from the directory that contains inventory/, or pass --inventory-path. Check that the paths are relative to the root. |
Best practices
- Pin the Kapitan version (
pip install kapitan==<version>or a fixed image tag) in CI and on workstations. Different versions can render different output. - Commit
compiled/if your team reviews generated manifests in pull requests. Otherwise, regenerate it in CI and check for differences. - Never use
sudo pip3 install. Root-level pip installs can break system tools that depend on Python packages managed by apt. - Store secrets with Kapitan refs (GPG, cloud KMS or Vault backends) instead of plain values in the inventory.
Frequently asked questions
Why does pip3 install –user kapitan fail on Ubuntu 24.04?
Ubuntu 23.04 and later mark the system Python as externally managed (PEP 668), so pip refuses to install into it. Install Kapitan in a virtual environment or with pipx install kapitan instead.
Where is the kapitan executable installed?
A --user or pipx install puts it in ~/.local/bin. A virtual environment install puts it in the environment's bin directory, for example ~/.venvs/kapitan/bin/kapitan.
How do I check which Kapitan version is installed?
Run kapitan --version. With Docker, the version depends on the image tag you pull, so pin a tag to keep it predictable.
Can I use Kapitan on macOS or Windows?
Yes. On macOS, use pipx, a virtual environment or the Docker image. On Windows, the most reliable option is WSL2 with the Ubuntu steps on this page, or Docker Desktop.
How do I upgrade Kapitan?
Run pip install --upgrade kapitan inside the virtual environment, pipx upgrade kapitan for pipx, or pull a newer image tag for Docker. Recompile afterwards and review any differences in compiled/.
Related tutorials
- More Docker tutorials
- More Linux tutorials
- How to Install and Configure pre-commit on macOS, Windows, and Linux: Complete Step-by-Step Guide
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals