Skip to main content

Command Palette

Search for a command to run...

How to install 'pyenv' Python version manager on Ubuntu 20.04

Updated
2 min read
How to install  'pyenv' Python version manager on Ubuntu 20.04
M

Hey, I'm a postgraduate in Cyber Security with practical experience in Software Engineering and DevOps Operations. The top player on TryHackMe platform, multilingual speaker (Kazakh, Russian, English, Spanish, and Turkish), curios person, bookworm, geek, sports lover, and just a good guy to speak with!

Overview:

pyenv - is a simple Python version manager tool, which allows you easily switch between multiple versions of Python. You can set local or global system-wide Python versions via the tool.

Installation:

  1. Install all required prerequisite dependencies:
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
  1. Download and execute installation script:
curl https://pyenv.run | bash
  1. Add the following entries into your ~/.bashrc file:
# pyenv
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
  1. Restart your shell:
exec $SHELL
  1. Validate installation:
pyenv --version

Uninstallation:

  1. Remove the ~/.pyenv folder
rm -rf ~/.pyenv
  1. Delete the following entries from your ~/.bashrc file:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
  1. Restart your shell
exec $SHELL

Basic commands:

  1. To install specific version use install flag:
pyenv install 3.8.0
  1. To list all available installed versions of Python on your system:
pyenv versions
  1. To set a specific version of Python global (system-wide) use global flag:
pyenv global 3.8.0
  1. To set a specific version of Python local (project-based) use local flag:
pyenv local 3.8.0

Reference:

  1. Command reference

  2. Troubleshooting / FAQ

More from this blog

M

Maxat Akbanov's blog

259 posts

Postgraduate in Cyber Security with experience in Software Engineering and DevOps Operations.