Install
$ sudo apt-get install -y 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 python3-openssl git
$ curl https://pyenv.run | bash
If we are using ZSH then we will now add the proper lines to our .zshrc.
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
Restart your shell so the path changes take effect:
$ exec $SHELL
Check python available versions:
$ pyenv versions
* system (set by /home/kali/.pyenv/version)
We can now install Python 2 and Python 3 versions:
$ pyenv install 2.7.18
Downloading Python-2.7.18.tar.xz...
-> https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz
Installing Python-2.7.18...
Installed Python-2.7.18 to /home/kali/.pyenv/versions/2.7.18
$ pyenv install 3.9.2
Downloading Python-3.9.2.tar.xz...
-> https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tar.xz
Installing Python-3.9.2...
Installed Python-3.9.2 to /home/kali/.pyenv/versions/3.9.2
kali@kali:~$ pyenv versions
* system (set by /home/kali/.pyenv/version)
2.7.18
3.9.2
Set python 2.7.18:
$ pyenv global 2.7.18
$ pyenv versions
system
* 2.7.18 (set by /home/kali/.pyenv/version)
3.9.2
Installation Location
$ ls ~/.pyenv/versions/
2.7.18 3.9.2
Removing versions:
$ rm -rf ~/.pyenv/versions/2.7.15
$ pyenv uninstall 2.7.15
Usage:
use version 2.7.18:
$ pyenv global 2.7.18
use python system’s version:
$ pyenv global system
You can see a complete list of all available commands with:
$ pyenv commands
$ pyenv command --help