Start off by installing build tools on RHEL8. You'll need them to check out various things from git and build them.

$ sudo dnf install -y \
        make \
        gcc \
        zlib-devel \
        bzip2 \
        bzip2-devel \
        readline-devel \
        sqlite \
        sqlite-devel \
        openssl-devel \
        tk-devel \
        libffi-devel \

Next up, clone the Pyenv git repository to your home directory.

$ git clone ~/.pyenv

I like to put all repositories downloaded from GitHub or BitBucket into separate directories. You can do whatever you want, but below structure helps keep things tidy in a hierarchy.

$ tree -d -L 2 code/
│   ├── some-random-repo0
│   └── some-random-repo1
├── codecommit
│   └── simple-flask-app
│   ├── ami-lister
│   ├── aws-secure-params
│   ├── aws-tools
│   ├── packer
│   ├── pyenv
│   ├── terraform-ec2-instance
│   ├── terraform-vault
│   ├── terraform-vpc-endpoints
│   └── tmux
└── taskcat-test

Anyway, now that you've cloned the pyenv git repository, setup some environment variables that point your $PATH variable to pyenv executable directory.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

Source your updated ~/.bash_profile file. This will reload your environment variables with updated $PATH variable.

$ source ~/.bash_profile

Now you are ready to install whatever Python version that you want. Below command will install Python 3.8.0 and set it as system default. Please note that your system will continue using whatever Python version it needs. You will be able to use the custom version of Python as long as your pyenv shims (environment variables) are loaded. Think of this like CentOS or Red Hat Software Collections.

$ pyenv install 3.8.0
$ pyenv global 3.8.0

You can view available versions for installation with:

$ pyenv versions


comments powered by Disqus