Installing Python 3.9 marks a significant step for developers seeking a stable release with performance improvements and new syntax features. This version introduced structural pattern matching, union types, and numerous optimizations that make it a robust choice for both new and existing projects.
Preparing Your System
Before you install Python 3.9, it is essential to prepare your operating system to avoid dependency conflicts. Depending on your distribution, you may need to update package lists and install build essentials to compile the source code successfully.
On Debian and Ubuntu
For users on Debian-based systems, opening the terminal and running the update command ensures you have the latest repository information. This step is crucial for pulling the correct libraries required for the installation process.
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev
On Red Hat and CentOS
If you are working on a Red Hat derivative, the package manager differs slightly, but the goal remains the same: install the development tools that provide the compilers and headers.
sudo yum groupinstall "Development Tools"
sudo yum install bzip2 bzip2-devel libffi-devel zlib-devel
Downloading the Python Source
To install Python 3.9 directly from the source, you must first download the official tarball from python.org. This method provides the most control over the installation and ensures you are using the genuine software.
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar -xf Python-3.9.0.tgz
cd Python-3.9.0
Compiling and Installing
Once the source is extracted, you configure the build environment to specify the installation prefix. Using --enable-optimizations activates Profile Guided Optimization (PGO), which makes the binary run faster.
./configure --enable-optimizations
make -j 4
sudo make altinstall
Note the use of altinstall rather than install . This practice prevents overwriting the default system Python binary, which protects the integrity of system tools that rely on the original version. Verifying the Installation After the compilation finishes, you should verify that Python 3.9 is active and correctly configured on your path. Checking the version provides immediate feedback on the success of the operation.
Verifying the Installation
python3.9 --version
This command should output "Python 3.9.x". If you encounter a "command not found" error, it usually indicates that the install directory is not included in your system's PATH environment variable.
Managing Pip and Virtual Environments
Ensure that the package installer is up to date to leverage the latest security patches and library compatibility. You can upgrade pip immediately after the Python installation.
python3.9 -m pip install --upgrade pip
Virtual environments are crucial for isolating project dependencies. Creating a new environment with Python 3.9 ensures that your projects do not interfere with one another.
python3.9 -m venv myproject
source myproject/bin/activate