Python 3.9 comes as a default with Fedora 34. However, sometimes you may wish to install older versions for development and test purposes. Apart from groupinstall
command, these instructions work for CentOS and REHL systems as well.
Install python development dependencies.
sudo dnf groupinstall "Development Tools"
sudo dnf install python3-devel openssl-devel zlib-devel bzip2-devel sqlite-devel libffi-devel
Note: You will need to rebuild and reinstall if you install new source or development libraries for python. Do not create or modify symlinks for python
, python3
, etc, as that may and will break many dependent libraries in your system.
Visit https://www.python.org/ftp/python/ for latest releases for version 3.8.X and download the .tgz
file. We will install Python-3.8.11
.
# download and extract source archive
wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz
tar xzf Python-3.8.11.tgz Python-3.8.11/
cd Python-3.8.11/
# configure with all optimizations
./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.8.11/
You can remove the .tgz
file, or keep it for future re-installation.
Visit https://www.python.org/ftp/python/ for latest releases for version 3.7.X and download the .tgz
file. We will install Python-3.7.10
.
# download and extract source archive
wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz
tar xzf Python-3.7.10.tgz Python-3.7.10/
cd Python-3.7.10/
# configure with all optimizations
./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.7.10/
You can remove the .tgz
file, or keep it for future re-installation.
Due to some changes in memory allocation architecture, installation of ensurepip
usually fails with gcc 11. An older gcc or clang is required. Install clang dependencies:
sudo dnf install clang llvm-devel
Visit https://www.python.org/ftp/python/ for latest releases for version 3.6.X and download the .tgz
file. We will install Python-3.6.13
.
# download and extract source archive
wget https://www.python.org/ftp/python/3.6.13/Python-3.6.13.tgz
tar xzf Python-3.6.13.tgz Python-3.6.13/
cd Python-3.6.13/
# configure with all optimizations
CC=clang LLVM_PROFDATA=/usr/bin/llvm-profdata ./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
CC=clang sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.6.13/
You can remove the .tgz
file, or keep it for future reinstallations.
Follow similar process as above.
helped!