How do I install Python on my server?
Python is most likely already on your server and working. If for some reason it's not broken, you can add it from DNF (YUM) or with WGET if DNF is failing. You can find the version you want here:
https://www.python.org/downloads/source/
Keep in mind some of the newer versions might not work with your OS or Control Panel version. You should ask them what version works best currently.
First, run the command below to install the required dependencies.
sudo dnf groupinstall "Development Tools" -y
sudo dnf install bzip2-devel libffi-devel openssl-devel -y
groupinstall installs the required development tools named Development Tools which is a collection of packages that are often used when compiling software from the source code.
Next, run the gcc command to make sure gcc is properly installed. Gcc is a compiler that is used to compile source code into binary files.
gcc --version
If you see a version number after the command, then gcc is installed and ready to use. If not, re-run the sudo dnf groupinstall "Development Tools" -y command above to install it.
Next, run the wget command to download the Python 3.6 source code from the Python official website. wget is a tool used to download files from the internet.
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Next, run the tar command to extract the downloaded Python 3.9 source code.
tar xvf Python-3.6.8.tar.xz
Next, run the cd command to change into the source code directory created with the previous tar. cd is a tool that allows us to navigate (change directories) in Linux.
cd Python-3.6.8/
Once you're in the source code directory, run the ./configure command to configure the Python source code for your system. The configure script will check your system for all required dependencies and install them if they’re not already installed. This can take a few minutes, so be patient.
./configure --enable-optimizations
make
sudo make install
Once the altinstall command is complete, Python 3.6 has been successfully installed on your system!
Run the python3 -V command again to verify that Python 3.6 has been installed and works correctly.
python3.6 --version
The output should show the Python 3.6.8 version number.