Before we talked about A Simple Way To Installing And Run Python And PIP On Windows and now will continue the same but on Linux CentOS Stream 8.
Installing Python On CentOS Stream 8
Update CentOS Stream and GroupInstall Development tools package
# dnf update # dnf groupinstall 'development tools' # dnf install openssl-devel bzip2-devel libffi-devel
Installing Python 2
Just installing using the following command
# dnf install python2 # python2 -V Python 2.7.18
python2-pip, and python2-setuptools packages will be installed too as dependencies.
By default app stream repositories contains python2, python36, python38, and python39 packages.
and you can search for new supported version newly added by #dnf search python
. So its simple to install Python 3.6
Installing Python 3
# dnf install python3
and the output will be similar to the following, the default version Python 3.6 is installed with PIP and Setuptools packages.
# dnf install python3 Last metadata expiration check: 0:28:39 ago on Sat 05 Mar 2022 04:22:45 PM UTC. Dependencies resolved. =========================================================================================================================================================================================== Package Architecture Version Repository Size =========================================================================================================================================================================================== Installing: python36 x86_64 3.6.8-38.module_el8.5.0+895+a459eca8 appstream 19 k Installing dependencies: python3-pip noarch 9.0.3-22.el8 appstream 20 k python3-setuptools noarch 39.2.0-6.el8 baseos 163 k Enabling module streams: python36 3.6 Transaction Summary =========================================================================================================================================================================================== Install 3 Packages
Installing Python 3.8
# dnf install python38
And the output will be similar to…
# dnf install python38 Last metadata expiration check: 0:40:47 ago on Sat 05 Mar 2022 04:22:45 PM UTC. Dependencies resolved. =========================================================================================================================================================================================== Package Architecture Version Repository Size =========================================================================================================================================================================================== Installing: python38 x86_64 3.8.12-1.module_el8.6.0+929+89303463 appstream 80 k Installing dependencies: python38-libs x86_64 3.8.12-1.module_el8.6.0+929+89303463 appstream 8.3 M python38-pip-wheel noarch 19.3.1-5.module_el8.6.0+960+f11a9b17 appstream 1.0 M python38-setuptools-wheel noarch 41.6.0-5.module_el8.6.0+929+89303463 appstream 304 k Installing weak dependencies: python38-pip noarch 19.3.1-5.module_el8.6.0+960+f11a9b17 appstream 1.8 M python38-setuptools noarch 41.6.0-5.module_el8.6.0+929+89303463 appstream 667 k Enabling module streams: python38 3.8 Transaction Summary =========================================================================================================================================================================================== Install 6 Packages
Installing Python 3.9
# dnf install python39
And the output will be similar to…
# dnf install python39 Last metadata expiration check: 0:45:08 ago on Sat 05 Mar 2022 04:22:45 PM UTC. Dependencies resolved. =========================================================================================================================================================================================== Package Architecture Version Repository Size =========================================================================================================================================================================================== Installing: python39 x86_64 3.9.7-1.module_el8.6.0+930+10acc06f appstream 33 k Installing dependencies: python39-libs x86_64 3.9.7-1.module_el8.6.0+930+10acc06f appstream 8.2 M python39-pip-wheel noarch 20.2.4-6.module_el8.6.0+930+10acc06f appstream 1.3 M python39-setuptools-wheel noarch 50.3.2-4.module_el8.6.0+930+10acc06f appstream 497 k Installing weak dependencies: python39-pip noarch 20.2.4-6.module_el8.6.0+930+10acc06f appstream 2.0 M python39-setuptools noarch 50.3.2-4.module_el8.6.0+930+10acc06f appstream 871 k Enabling module streams: python39 3.9 Transaction Summary =========================================================================================================================================================================================== Install 6 Packages
But now we installed multiple Python from version 3 (3.6, 3.8, and 3.9), so we can switch between them using alternatives
command
and if we need to check the current default Python 3 version
# python3 --version
Python 3.6.8
Switch Between Python 3 Versions
# alternatives --config python3
The output will be similar to the following.
# alternatives --config python3
There are 3 programs which provide 'python3'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/python3.6
2 /usr/bin/python3.8
3 /usr/bin/python3.9
Enter to keep the current selection[+], or type selection number:
To select Python3.9 as an alternative press 3, then Enter and when checking the default python 3 again it will be similar to the following
# python3 --version
Python 3.9.7
Installing Python 3.10 From Source
Till now, Python 3.10 has not been included in the app stream, so we can install it from the source as the following steps
After Updating and Install the dependencies packages as the first step above, download the latest source from the python website current version is Python 3.10.2
# curl https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz -O # tar xzvf Python-3.10.2.tgz # cd Python-3.10.2 # ./configure --enable-optimizations
Now we need to run # make install
, But if you installed another previous version before or have multiple python binaries, so the best is to use # make altinstall
# make install OR # make altinstall
Altinstall will keep the default system python binary one without change.