Kapitan is a Python-based configuration management tool, and on Windows it runs best inside the Windows Subsystem for Linux (WSL). This guide fills in the commands the steps above leave out: installing WSL and Ubuntu, installing Kapitan cleanly with pipx or a virtual environment on current Ubuntu releases, checking it with a small compile test, and fixing the errors people hit most often.
Step 1 – Install WSL
Step 2 – Install Ubuntu WSL image from Microsoft Store
Step 3 – Login to ubuntu wsl and install Kapitan
$ sudo apt-get update && sudo apt-get install -y python3.8-dev python3-pip python3-yaml
$ pip3 install --user --upgrade kapitan
$ sudo pip3 install --upgrade kapitan
$ kapitan --versionCode language: JavaScript (javascript)
Prerequisites
- Windows 11, or Windows 10 version 2004 (build 19041) or later, so the single
wsl --installcommand is available. - Virtualization turned on in the BIOS/UEFI. WSL 2 needs it.
- An administrator PowerShell or Windows Terminal session for the WSL install.
- Internet access from inside WSL to reach the Ubuntu package mirrors and PyPI.
Kapitan pulls in dependencies such as Jinja2, Jsonnet bindings and Kadet, so it needs a working Python 3 toolchain. The steps below use whatever Python 3 ships with your Ubuntu release and do not pin a specific minor version.
Steps 1 and 2: install WSL and Ubuntu
You don't need to visit the Microsoft Store as a separate step. A single command enables the WSL features, installs the WSL 2 kernel and adds Ubuntu as the default distribution. Run it in an administrator PowerShell:
# Install WSL with the default Ubuntu distribution
wsl --install
# Or list the available distributions and pick a specific one
wsl --list --online
wsl --install -d Ubuntu-24.04Code language: PHP (php)
Restart Windows when prompted. On first launch, Ubuntu asks you to create a Linux username and password. This account is separate from your Windows login, and sudo will ask for this password. Then confirm the distribution is running under WSL 2:
wsl --list --verbose
# Expected output (similar to)
# NAME STATE VERSION
# * Ubuntu-24.04 Running 2
# If VERSION shows 1, convert it
wsl --set-version Ubuntu-24.04 2Code language: PHP (php)
Note: For more PowerShell basics, see the PowerShell command line reference.
Step 3 corrected: install Kapitan inside Ubuntu
The command block above will fail on current Ubuntu images. The fixed approach installs the generic Python packages, then installs Kapitan into its own isolated environment so it never touches the system Python. Open the Ubuntu terminal and use one of the options below.
Option A: pipx (recommended for a command-line tool). pipx creates a private virtual environment for Kapitan and puts the kapitan command on your PATH.
sudo apt update
sudo apt install -y python3 python3-dev python3-venv pipx build-essential git
pipx ensurepath # adds ~/.local/bin to PATH
exec $SHELL -l # reload the shell so the PATH change applies
pipx install kapitan
kapitan --versionCode language: PHP (php)
Option B: a virtual environment. Use this if you want to pin Kapitan per project or install extra Python libraries next to it.
sudo apt update
sudo apt install -y python3 python3-dev python3-venv python3-pip build-essential git
python3 -m venv ~/.venvs/kapitan
source ~/.venvs/kapitan/bin/activate
pip install --upgrade pip
pip install kapitan
kapitan --versionCode language: JavaScript (javascript)
python3-dev and build-essential provide the headers and compiler that pip needs if a dependency has no prebuilt wheel for your Python version. kapitan --version should print a version number. With Option B, run source ~/.venvs/kapitan/bin/activate in each new terminal before you use kapitan.
Alternative: run Kapitan from the Docker image
If you already use Docker Desktop with WSL integration turned on for your Ubuntu distribution, you can skip the Python setup and use the official kapicorp/kapitan image. Run it from the root of your Kapitan repository:
docker run -t --rm -u $(id -u) -v $(pwd):/src:delegated kapicorp/kapitan --version
# Optional alias so it behaves like a local install
alias kapitan='docker run -t --rm -u $(id -u) -v $(pwd):/src:delegated kapicorp/kapitan'
kapitan compileCode language: PHP (php)
-u $(id -u) makes compiled files belong to your WSL user instead of root, and -v $(pwd):/src mounts the current directory where the container expects the project.
Verify the install with a first compile
A version number shows the binary runs. A small compile shows that the inventory and templating also work. Create the project in your Linux home directory, not under /mnt/c, because file access across the Windows boundary is much slower.
mkdir -p ~/kapitan-demo/inventory/targets ~/kapitan-demo/templates
cd ~/kapitan-demo
cat > inventory/targets/dev.yml <<'EOF'
parameters:
greeting: Hello from Kapitan on WSL
kapitan:
vars:
target: dev
compile:
- output_path: .
input_type: jinja2
input_paths:
- templates/hello.txt
EOF
cat > templates/hello.txt <<'EOF'
{{ inventory.parameters.greeting }} (target: {{ inventory.parameters.kapitan.vars.target }})
EOF
kapitan compile
cat compiled/dev/hello.txtCode language: PHP (php)
Kapitan reads every file in inventory/targets/ as a target, renders the Jinja2 template with the inventory available as inventory, and writes the result to compiled/<target>/. The last command should print Hello from Kapitan on WSL (target: dev).
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
E: Unable to locate package python3.8-dev | Ubuntu 22.04 and 24.04 do not ship Python 3.8 in their default repositories. | Install python3-dev, which matches the system Python. |
error: externally-managed-environment | Ubuntu 23.04 and later block pip install into the system Python (PEP 668). | Use pipx or a virtual environment. Don't use --break-system-packages. |
kapitan: command not found | ~/.local/bin is not on PATH, or the venv is not activated. | Run pipx ensurepath and reopen the shell, or source ~/.venvs/kapitan/bin/activate. |
Build fails with gcc or Python.h errors | A dependency is compiling from source without build tools. | Install build-essential and python3-dev, then retry. |
No matching distribution found for kapitan | Your Python version is outside the range the current Kapitan release supports. | Check the Requires-Python value on Kapitan's PyPI page, then use a matching Python or the Docker image. |
wsl --install only prints help text | WSL is already partly installed on the machine. | Run wsl --install -d Ubuntu to add the distribution directly. |
Upgrading, uninstalling and good practice
# pipx install
pipx upgrade kapitan
pipx uninstall kapitan
# venv install
source ~/.venvs/kapitan/bin/activate
pip install --upgrade kapitan
deactivate && rm -rf ~/.venvs/kapitanCode language: PHP (php)
- Never run
sudo pip install. It can overwrite Python packages thataptand Ubuntu tools rely on. - Pin the Kapitan version per repository (for example
pip install kapitan==<version>in a venv, or a fixed Docker image tag) so the whole team and CI compile the same output. - Keep Kapitan repositories inside the WSL filesystem and open them from Windows editors through the
\\wsl$path or VS Code's WSL extension. - Kapitan can manage secrets through references backed by GPG, Vault or cloud KMS. Commit only the reference files, never plaintext secrets.
Frequently asked questions
Can Kapitan run natively on Windows without WSL?
Kapitan is developed and tested mainly on Linux and macOS, and some of its dependencies are difficult to build on native Windows. WSL or the Docker image is the reliable way to run it on a Windows machine.
Which Ubuntu version should I use in WSL for Kapitan?
A current LTS release such as Ubuntu 22.04 or 24.04 works. If the system Python is outside the range a Kapitan release supports, use the Docker image or install a matching Python version.
Why does pip install kapitan fail with externally-managed-environment?
Newer Ubuntu releases mark the system Python as managed by apt and refuse global pip installs. Install Kapitan with pipx or inside a virtual environment instead.
How do I check that Kapitan is installed correctly?
Run kapitan --version to confirm the command works. Then run kapitan compile on a small test inventory and check that output files appear under compiled/<target>/.
Should I install Kapitan with both pip –user and sudo pip?
No. The original commands install it twice, and sudo pip changes the system Python. A single pipx or virtual environment install is enough.
Related tutorials
- Powershell Tutorials: Command Line reference
- How to Install and Configure pre-commit on macOS, Windows, and Linux: Complete Step-by-Step Guide
- More Linux tutorials
- More Windows tutorials
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