Pyenv is a Python version manager. It is recommended, because it does not depend on Python, (written in Bash) and using it we can install and utilize multiple Python versions without affecting the Python version used by MacOS.
The Pyenv source code is at https://github.com/pyenv/pyenv
We will use Homebrew to install Pyenv
brew install pyenv
Install the latest stable version of Python with Pyenv
Check https://www.python.org/downloads/macos/ for the latest stable release.
pyenv install 3.11.1
Set the new Python version the default
pyenv global 3.11.1
# check if the change took effect
Configure your shell to use Pyenv for Python version management
Add these lines to your .bashrc, .zshrc or .bash_profile file
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"