Koki's personal blog

Koki's personal blog

Another fine, responsive site template by HTML5 UP.

How to Install pyenv on WSL2 Ubuntu 22.04

In this article, we'll walk you through the steps to install pyenv on Ubuntu 22.04 running on WSL2. From introducing the packages needed for pyenv's installation to setting up pyenv itself, we cover the complete process.

Koki

1-Minute Read

In this article, we’ll walk you through the steps to install pyenv on Ubuntu 22.04 running on WSL2. From introducing the packages needed for pyenv’s installation to setting up pyenv itself, we cover the complete process.

The following lists are the table of contents about this article.

Target audience

  • Those using WSL2
  • Individuals looking to manage Python versions efficiently
  • Those aiming to install pyenv on Ubuntu

Environment

  • WSL2
  • Ubuntu 22.04

Preconditions

  • Can access to the internet

Contents

1. Installing Necessary Packages

First, we need to install the packages required for pyenv. Execute the following command:

sudo apt install -y gcc make build-essential libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev liblzma-dev

2. Installing pyenv

Next, we’ll use the official installation script to get pyenv set up.

curl https://pyenv.run | bash

3. Initial Configuration for pyenv

Lastly, set up the environment variables for pyenv. Add the following lines to your .bashrc:

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

With these steps, you should now have pyenv installed and ready to use on Ubuntu 22.04 on WSL2.

Reference articles

Recent Posts

Categories