Pyenv is an excellent tool for installing and managing several Python versions. It keeps the system tidy and clear of unused package bloat. It enables developers to access newer versions of Python smoothly. Additionally, it allows users to specify the Python version that a particular project uses. That immediately transitions to that version. It also enables easy version switching between Python versions. This guide covers installing Pyenv on Ubuntu 18.04, 20.04, and 23.04. For those interested in enhancing their server’s security setup, there’s an excellent resource. Especially on configuring firewalls in Ubuntu that you might find particularly useful.

Many people use the utility Pyenv to handle various Python versions on a single system. It enables simple installation, switching, and management. Enables many Python versions for your development projects. You can establish isolated Python environments and guarantee compatibility. Specifically with particular Python versions required by your apps by using Pyenv. You can follow the instructions in this article to install Pyenv on Ubuntu 18.04, 20.04, 22.04, 23.04.

Step-to-Step Guide for Installing Pyenv on Ubuntu 20.04 | 22.04

Step 1: Install and Update Dependencies

Starting any installation process by updating system packages is usually a good idea:

root@ubuntu:~# apt update -y

Run the following command to install all of pyenv’s dependencies after that has finished:

root@ubuntu:~# apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git

Step 2: In this Step, you need to Download the Script of Pyenv in Ubuntu

With the following command and the present step, download the script of Pyenv:

$ curl https://pyenv.run | bash

Step 3: Set the Environment Up

Run the following block of commands to set certain crucial environment variables and set up pyenv autocompletion in order to correctly configure pyenv for use on the system:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc

Finally, restart the shell by running: to begin utilizing pyenv.

root@ubuntu:~# exec "$SHELL"

Step 4: Look over the Installation

We will attempt to install a fresh copy of Python to make sure Pyenv is set up properly. The Python versions that are currently available are listed first:

root@ubuntu:~# pyenv install --list

The list of versions that are offered is extensive. Let’s install Python version 3.8.3 now:

root@ubuntu:~# pyenv install 3.8.3
Downloading Python-3.8.3.tar.xz...
-> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
Installing Python-3.8.3...
Installed Python-3.8.3 to /root/.pyenv/versions/3.8.3

If this command takes a while to execute, do not be alarmed. Pyenv is building this version of Python from the source code.

Run the pyenv versions command to see if Python 3.8.3 has now been installed:

root@ubuntu:~# pyenv versions
* system (set by /root/.pyenv/version)
3.8.3

Change Python to version 3.8.3 and then drop it into a Python shell to perform additional checking.

root@ubuntu:~# pyenv global 3.8.3
root@ubuntu:~# python
Python 3.8.3 (default, Jun 10 2020, 22:45:23)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Commands Useful

Finally, execute the following command to get a sense of all the commands and features that pyenv has to offer:

root@ubuntu:~# pyenv help
Usage: pyenv <command> [<args>]

Wrapping Up on the Installation of Pyenv on Ubuntu 20.04 | 22.04

It’s simple to manage Python versions and build isolated environments for your projects on Ubuntu 18.04 by installing pyenv. You may quickly switch between various Python versions with pyenv, ensuring flexibility and compatibility in your development workflow. You may successfully set up Pyenv and start using its capabilities to speed up your Python development process by following the instructions provided in this article.

When you conclude you will have a clear picture or concept about installing pyenv on Ubuntu on versions 18.04, 20.04, or 22.04, 23.04, etc. To manage multiple websites or database functionalities you need VestaCP to install on Ubuntu. We tried to explain to you in a simple and detailed way all the basics and steps for the installation. Hope you got things clear through this.