steps to install pyenv

pyenv is a tool to manage different versions of python installation. This post summarize the steps that I take in order to install pyenv tool. You can also reference the steps in the pyenv installer as below:

https://github.com/pyenv/pyenv-installer

However, the installer failed to configure the environment variables in my Ubuntu Linux, so I record some steps here.

Step 1: run the below command to install pyenv

curl https://pyenv.run | bash

Step 2: configure the environment variable in ~/.bashrc file

export PATH=”$HOME/.pyenv/bin:$PATH”
eval “$(pyenv init –path)”
eval “$(pyenv init -)”
eval “$(pyenv virtualenv-init -)”

note:

  • eval “$(pyenv init –path)” is used to add the path of the pyenv shims to the PATH environment variable.
  • eval “$(pyenv init -)” is used to enable command auto-completion and add some sub-commands.
  • eval “$(pyenv virtualenv-init -)” is used to activates a Python virtualenv environment based on current pyenv version

Step 3: install any python version you like

pyenv install 3.8.11

Before running this step, you need to logout the current shell session and login again. What’s more, you are also required to install some tools required to build python package as below:

https://github.com/pyenv/pyenv/wiki#suggested-build-environment

Step 4: select a specific version of the installed python to be used in the current shell.

pyenv global 3.8.11

This tool is really excellent when you need to switch different versions of python installation.