Option 1: Install Python From Package Manager
The newest Python 3 version available in the package manager is Python 3.6.8. For the latest major release, you need to install the package from the source code. For instructions on how to do so, refer to the next section. If you prefer installing version 3.6.8, follow the steps listed below.
1. Start by updating the repository:
sudo yum update -y
2. Install Python 3 by running the following command in the terminal window:
sudo yum install -y python3
3. Verify you have successfully installed Python 3 with:
python3 --version
Option 2: Install Python From Source Code
To install the latest major release of Python, which is 3.9.6 (at the time of writing), you need to download a copy of the source code and take some additional steps when setting up.
1. First, install the required packages and dependencies:
sudo yum groupinstall "Development Tools" -y
sudo yum install gcc open-ssl-devel bzip2-devel libffi-devel -y
_____________________________________________________________________________
Install OpenSSL on CentOS 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf update sudo dnf group install 'Development Tools' sudo dnf install perl-core zlib-devel
Step 2. Installing OpenSSL on CentOS 8.
Now we download the latest stable version OpenSSL from the official page:
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
Next, extract the downloaded file using the command below:
tar -xzvf openssl-1.1.1k.tar.gz
Then, navigate to the extracted directory:
cd openssl-1.1.1k
Now it’s time to configure and compile OpenSSL:
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib make make test sudo make install
Once we have successfully installed OpenSSL, configure its shared libraries:
cd /etc/ld.so.conf.d/ nano openssl-1.1.1k.conf
Add the following path in the config file:
/usr/local/ssl/lib
Save and exit and now reload the dynamic link using the command below:
ldconfig -v
Step 3. Configure OpenSSL Binary.
First, backup the default OpenSSL binary files:
mv /bin/openssl /bin/openssl.backup
Next, create new environment files for OpenSSL:
nano /etc/profile.d/openssl.sh
Add the following line:
OPENSSL_PATH="/usr/local/ssl/bin" export OPENSSL_PATH PATH=$PATH:$OPENSSL_PATH export PATH
Next, make the openssl.sh
file executable by issuing the command below:
chmod +x /etc/profile.d/openssl.sh
Then, reload the new OpenSSL environment file and check the default PATH:
source /etc/profile.d/openssl.sh echo $PATH
Finally step, verify our installation of the latest stable version of OpenSSL using the command below:
which openssl openssl version -a
Congratulations! You have successfully installed OpenSSL. Thanks for using this tutorial for installing the OpenSSL on your CentOS 8 system. For additional help or useful information, we recommend you check the official OpenSSL website.
_____________________________________________________________________________
2. Next, use the wget
command to download the desired Python version. If you don’t have wget
, install it by simply running:
sudo yum install wget -y
To download Python 3.9.6, use the command:
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
3. Extract the package:
sudo tar xzf Python-3.9.6.tgz
4. Then, move to the directory:
cd Python-3.9.6
5. Once in the Python directory, compile the source code into an installation package with the following two commands:
./configure --enable-optimizations
make altinstall
The make
command builds the installer package. The altinstall
command instructs the system to create a second installation of this version of Python. Without it, the system would replace the default version of Python.
6. Check the Python version to verify the installation:
python3.9