This tutorial will show how to install pyenv on Ubuntu and other Debian distributions, so you can quickly switch between Python versions.
sudo apt-get 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
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
The command below should print the installed version:
pyenv -v
which in my case printed:
pyenv 2.1.0
If it doesn’t, then add the following lines at the end of your:
.bashrc
if you use bash.zshrc
if you use zshexport PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init --path)" fi eval "$(pyenv virtualenv-init -)"
Then reload your shell and it should work.
Run the command below to list the available Python versions to be installed:
pyenv install --list
Which should yield something like:
Available versions: 2.1.3 2.2.3 ... 3.10.0 3.10-dev 3.11.0a1 3.11-dev
Then, pick a version of your choice and install it running the following command:
pyenv install 3.10.0
Finally, set the installed version as the default local (to this terminal session) or global (entire system):
pyenv local 3.10.0
This guide will show you how to create a Python function decorator with a few…
This guide will show you how to fix the error Got permission denied while trying…
This guide will show you how to create a Python virtual environment on Intellij IDEA…
This tutorial will quickly show you how to to find and kill processes on Linux,…
This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…
I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…
View Comments
Absolutely love this page. It's my go-to reference to install pyenv. Just wish that the "copy" button's didn't also copy the leading "~ $"...
Thanks for the feedback! I removed the leading “~ $” and split a command that had the output in the same box, so it should be better to copy them now :)
I will try to figure out a non-intrusive way to format the command boxes with the “~ $” prefix later.
Praise be! Thank you so much!!!
Installed it as instructed but the files were all littered with Windows line returns. Had to use dos2unix on all of the files before it would work...
Nowadays (I'm running pyenv version 2.2.5) the .bash/.zshrc config must look different:
```
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
```
Works for me.
Please add git to the list of dependencies that need to be installed.
Normally you need to install git manually on Alpine and Solus distros, but Ubuntu should already have it on a fresh install. Which distro are you using?
show
Thank you!!!!
Thanks