Python is now a widely used programming language in various fields including Machine learning and AI. It is a versatile language known for its clarity and readability. Despite the latest versions of the programming language developers often need to work on some old software that requires specific versions of Python to ensure compatibility with their projects.
If such is the case with you, here we see the process of installing Python 3.8 on an Amazon Linux 2023 system in this article.
Prerequisites
To follow this tutorial, we are assuming that you already have access to Amazon Linux 2023 instance on the AWS cloud along with sudo rights to run administrative commands.
Step 1: Update AL2023 Packages
If you are accessing your Amazon Linux 2023 after quite a while, execute the system update command to update the package information. It will also install the updates for existing packages.
sudo dnf update -y
Step 2: Install Development Tools
Python 3.8 is not available to install using the Amazon Linux 2023’s default repositories, so we will compile this version using its source file. Therefore, we required some specific development tools and libraries. Use the following command to install the necessary packages:
sudo dnf groupinstall "Development Tools"
Step 3: Install Dependencies
There are further dependencies that are needed for the smooth installation of Python, here are those to install using the given command.
sudo dnf install -y openssl-devel bzip2-devel libffi-devel zlib-devel
Step 4: Download and Compile Python
Now, let’s download and compile Python 3.8 source code on our Amazon 2023 Linux, first, navigate to the /opt directory:
cd /opt
Next, use the wget command line tool to download the Python 3.8.12 source code:
sudo wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
You can visit – https://www.python.org/ftp/python/ for other versions such as 3.8.0, 3.8.1.. etc, if needed. Alternatively, you can just change the version in the above command to get the source code file.
Note, if you don’t have wget then can get it using: sudo dnf install wget
Extract the Python 3.8 archive, once it is downloaded successfully:
sudo tar xzf Python-3.8.12.tgz
After that navigate to the extracted folder:
cd Python-3.8.12
Configure the build:
sudo ./configure --enable-optimizations
Start the compilation process:
sudo make altinstall
Step 5: Verify Python 3.8 on Amazon Linux 2023
As you have executed all the above-given commands and the system is done with the process of compiling and installation, check if Python 3.8 is installed successfully on your Amazon Linux 2023 or not.
python3.8 --version
This command should display the Python version as 3.8.12 because we have installed it.
Step 6: Clean Up
Now, you can remove the downloaded Python source files to free up some space:
sudo rm -rf /opt/Python-3.8.12
Step 7: Set Python 3.8 as the default version
Like most of the Linux distros, Amazon Linux 2023 also uses the “alternatives” command to manage default tools. So, to set Python 3.8 as the default version, you need to update the alternatives for the python3 command:
sudo alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.8 1
or Configure Alternatives
If you have multiple versions of Python then you need to configure the alternatives system to select Python 3.8 as the default version when you run the python3 command.
sudo alternatives --config python3
The above command output will give you a list of available alternatives. Select the number corresponding to /usr/local/bin/python3.8 to set it as the default version.
To confirm that Python 3.8 is now the default version, run:
python3 --version
Conclusion
So, this was the quick way to get the old version of Python which is 3.8 on the latest Amazon Linux 2023 to develop and run projects using this version of Python. Remember, this tutorial is not just limited to Python 3.8 but even can be used to configure other versions of it as well.
Other Articles: