How to Install Pyenv on Ubuntu 24.04

Due to the slowness of repositories or even lack thereof being updated with specific versions of Python, I’ve decided to move some of my environments over to Pyenv to allow me to dynamically install and configure Python specifically for my environment….


This content originally appeared on DEV Community and was authored by Emdadul Huq

Due to the slowness of repositories or even lack thereof being updated with specific versions of Python, I’ve decided to move some of my environments over to Pyenv to allow me to dynamically install and configure Python specifically for my environment. As it turns out this will also allow VS Code to allow me to choose the version of Python that I’d like to use when testing. So, here’s a quick guide to installing Pyenv on Ubuntu 24.04

Update and install dependencies

we need to ensure our package cache is updated, and then install the dependencies to download, and build python from pyenv.

sudo apt-get update && sudo apt-get install make build-essential 

Install Pyenv using pyenv-installer

curl https://pyenv.run | bash

Configure user profile to use pyenv

Ensure the following is in your ~/.bash_profile (if exists), ~/.profile (for login shells), ~/.bashrc (for interactive shells), or ~/.zshrc

# Load pyenv automatically by appending
# the following to 
# ~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
# and ~/.bashrc (for interactive shells) :

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Optionally enable pyenv-virtualenv

eval "$(pyenv virtualenv-init -)"

Reload your profile

source ~/.profile

Install python using pyenv

pyenv install <version> 

Set your python version

pyenv shell — select just for current shell session
pyenv local — automatically select whenever you are in the current directory (or its subdirectories)
pyenv global — select globally for your user account

Validate your installation of python

python3 --version

Reference Pyenv

Sample


This content originally appeared on DEV Community and was authored by Emdadul Huq


Print Share Comment Cite Upload Translate Updates
APA

Emdadul Huq | Sciencx (2024-07-25T06:07:36+00:00) How to Install Pyenv on Ubuntu 24.04. Retrieved from https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/

MLA
" » How to Install Pyenv on Ubuntu 24.04." Emdadul Huq | Sciencx - Thursday July 25, 2024, https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/
HARVARD
Emdadul Huq | Sciencx Thursday July 25, 2024 » How to Install Pyenv on Ubuntu 24.04., viewed ,<https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/>
VANCOUVER
Emdadul Huq | Sciencx - » How to Install Pyenv on Ubuntu 24.04. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/
CHICAGO
" » How to Install Pyenv on Ubuntu 24.04." Emdadul Huq | Sciencx - Accessed . https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/
IEEE
" » How to Install Pyenv on Ubuntu 24.04." Emdadul Huq | Sciencx [Online]. Available: https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/. [Accessed: ]
rf:citation
» How to Install Pyenv on Ubuntu 24.04 | Emdadul Huq | Sciencx | https://www.scien.cx/2024/07/25/how-to-install-pyenv-on-ubuntu-24-04/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.