Quick guide: Install pyenv on Ubuntu / Pop!_OS 22.04 and manage Python 3.12 & 3.11
Harrys Kavan

Harrys Kavan @zwarag

About: Teaching sand how to think.

Location:
Vienna, Austria
Joined:
Jun 2, 2021

Quick guide: Install pyenv on Ubuntu / Pop!_OS 22.04 and manage Python 3.12 & 3.11

Publish Date: Jun 11
0 1

Need multiple Python versions without fighting apt? pyenv is the cleanest way.
Below is the 5-minute setup I use on Pop!_OS 22.04 (LTS) — it works the same on vanilla Ubuntu 22.04.

1 · Prereqs – dev libraries & build tools

pyenv compiles CPython from source, so we have to give its build script every *-dev dependency it needs.

sudo apt update
sudo apt install -y \
  make build-essential            \
  libssl-dev zlib1g-dev           \
  libbz2-dev libreadline-dev      \
  libsqlite3-dev libncursesw5-dev \
  liblzma-dev tk-dev              \
  curl git                         # helpers
Enter fullscreen mode Exit fullscreen mode

(If you already did this, you’re golden.)


2 · Install pyenv

# 1) Clone pyenv into ~/.pyenv
curl https://pyenv.run | bash

# 2) Add it to your shell
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'eval "$(pyenv init --path)"\n' >> ~/.bashrc
exec $SHELL          # reload the shell
Enter fullscreen mode Exit fullscreen mode

Zsh? Drop the lines into ~/.zshrc.


3 · Build the Pythons you need

# Latest patch releases as of June 2025
pyenv install 3.12.11   # newest stable
pyenv install 3.11.9    # LTS-ish for many libs
Enter fullscreen mode Exit fullscreen mode

Grab a coffee — the first build can take a few minutes.


4 · Make Python 3.12 your global default

pyenv global 3.12.11
python --version        # → Python 3.12.11
Enter fullscreen mode Exit fullscreen mode

Switch projects on-the-fly:

pyenv local 3.11.9      # writes .python-version in the folder
Enter fullscreen mode Exit fullscreen mode

5 · Bonus: keep everything tidy

  • Uninstall a version: pyenv uninstall 3.11.9
  • List what’s installed: pyenv versions
  • Update pyenv itself: git -C "$(pyenv root)" pull

That’s it!

You now have a sandboxed Python 3.12 interpreter (with SSL, readline, curses, etc.) plus 3.11 for legacy projects — all without touching the system Python that apt depends on. Happy hacking!

Comments 1 total

  • Richard
    RichardJun 11, 2025

    Hi there! receive your guaranteed a $15 bonus in blockchain rewards quick! — Join now! Bonus unlocks after wallet connect. 👉 duckybsc.xyz

Add comment