Run it as root
Install software requirements
yum install gcc openssl-devel bzip2-devel libffi-devel -y
Download Python 3.9.2 and extract files
mkdir downloads
cd downloads
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar -xzf Python-3.9.5.tgz
cd Python-3.9.5/
Compile and Install
Note: If you don’t have sudo permissions don’t use –enable-shared and change the –prefix to –prefix=/home/username/python3 (where python3 is the folder where you want the new Python to be installed.
./configure --prefix=/usr/local --enable-ipv6 --enable-loadable-sqlite-extensions --enable-optimizations --enable-shared
make altinstall
or this if you don't want enable-shared
./configure --prefix=/usr/local --enable-optimizations
make altinstall
With –eanabled-shared you will get the following eror
which python3
python3.9: error while loading shared libraries: libpython3.9.so.1.0: cannot open shared object file: No such file or directory
The fix
ldconfig /usr/local/lib
Or even better, create a python3.conf file and run ldconfig after that
cd /etc/ld.so.conf.d/
touch python3.conf
Add the following in python3.com
/usr/local/lib
Then run ldconfig
Create shortcut
ln -s /usr/local/bin/python3.9 /usr/bin/python3
Check again
which python3
/usr/bin/python3