Step-by-Step Guide: Setting Up pyenv

Rohit Vishwakarma
2 min readDec 17, 2023

--

Install the required dependencies, run the following command

sudo apt update
# for Debian/Ubuntu
sudo apt install -y git curl make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
# for CentOS/RHEL
sudo yum install -y git gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel

Setting up pyenv using binary file:

# Cloning pyenv 
sudo git clone https://github.com/pyenv/pyenv.git /usr/local/pyenv

Add pyenv to the system's environment variables by modifying the system-wide shell configuration file (e.g., /etc/profile or /etc/environment):

Open the configuration file in a text editor. For example:

sudo vim /etc/profile

Add the following lines at the end of the file:

export PYENV_ROOT="/usr/local/pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Apply Changes:
To apply the changes to the current session, you can either log out and log back in or use the source command:

source /etc/profile

Verify Installation:
You can verify that pyenv is installed correctly by running:

# Check version
pyenv --version

Install Python Versions:
Users can now use pyenv to install and manage Python versions. For example, to install Python 3.8.12, run:

# To install python3.11
pyenv install 3.11

Set a Global Python Version (optional):
To set a global Python version for all users, you can use the pyenv global command. For example:

# Set the python3.11 as global 
pyenv global 3.11

Now, all users on your Ubuntu server should be able to use pyenv to manage their Python environments. They can install different Python versions and create virtual environments as needed.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response