Wednesday, May 5, 2021

Installing Python from source on a Fedora Linux system

I have a need to install a new version of Python on a dated Fedora Linux system (Fedora 31). Here is the steps that I followed,


# install neccessary packages to build Python from source
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel

# download Python source package. You may select a different version you wish 
# to download by browsing https://www.python.org/ftp/python/
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz

# extract the files from the package
tar xzf Python-3.9.5.tgz

# go to the directory where the extracted files are
cd Python-3.9.5

# enable optimization
sudo ./configure --enable-optimizations

# compile and install to /usr/local
sudo make altinstall

# show the version of the active Python
python --version

# add the newly installed Python to alternatives (I already have a Python2 Python3.7)
sudo alternatives --install /usr/bin/python python /usr/local/bin/python3.9 3

# config alternatives and select 3 as the active Python
sudo alternatives --config python

# check the version of the active Python
python --version

No comments:

Post a Comment