FedoraRHEL Based

How To Install Python on Fedora 40

Install Python on Fedora 40

In this tutorial, we will show you how to install Python on Fedora 40. Python is a versatile and powerful programming language widely used for development, scripting, and data analysis. With its extensive ecosystem of libraries and frameworks, Python has become an essential tool for developers and data scientists alike. Fedora 40, the latest release of the popular Linux distribution, provides a stable and secure platform for running Python applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Python programming language on Fedora 40.


Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A server running one of the following operating systems: Fedora 40.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
  • A stable internet connection to download the necessary packages.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Python on Fedora 40

Step 1. Update the System.

To begin, open the terminal and run the following command to update your system packages to the latest versions:

sudo dnf clean all
sudo dnf update

This command will fetch and install any available updates, ensuring that your Fedora 40 system is up to date and ready for Python installation.

Step 2. Installing Python on Fedora 40.

  • Installing Python Using DNF

Fedora 40 comes with the DNF package manager, which simplifies the installation of software packages. To install Python using DNF, follow these steps:

sudo dnf install python3

Once the installation is complete, you can verify the installed Python version by running:

python3 --version

This command will display the version number of Python 3 installed on your system.

By default, Fedora 40 installs the latest stable version of Python 3. If you require a specific version, you can specify it during the installation command. For example, to install Python 3.8, use:

sudo dnf install python39

With Python installed using DNF, you’re ready to start developing and running Python applications on your Fedora 40 system.

  • Using Pyenv for Python Version Management

While DNF provides a straightforward way to install Python versions, an alternative approach is to use Pyenv, a powerful tool for managing multiple Python versions on your system. Pyenv allows you to easily install, switch between, and manage different Python versions without affecting the system-wide Python installation.

To install Pyenv on Fedora 40, follow these steps:

sudo dnf install git gcc zlib-devel bzip2-devel readline-devel sqlite-devel openssl-devel

Clone the Pyenv repository:

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Add Pyenv to your shell environment:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Restart your shell or run the following command to apply the changes:

source ~/.bashrc

With Pyenv installed, you can now easily install and manage different Python versions. To install a specific Python version using Pyenv, use the following command:

pyenv install 3.8.1

To set a global Python version for your system, use:

pyenv global 3.8.1

You can also set a local Python version for a specific project directory using:

pyenv local 3.8.1

This command will create a .python-version file in the current directory, specifying the Python version to be used for that project.

Pyenv provides a convenient way to manage multiple Python versions, allowing you to easily switch between them based on project requirements. It helps maintain a clean and organized Python development environment on your Fedora 40 system.

  • Installing Python from Source

In addition to the standard installation methods using DNF and Pyenv, there are a few advanced installation methods that you may find useful in certain scenarios:

wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz

Extract the downloaded archive:

tar xzf Python-3.12.3.tgz

Navigate to the extracted directory:

cd Python-3.12.3

Configure the build with optimizations:

./configure --enable-optimizations

Build and install Python:

sudo make altinstall

Installing Python from the source allows you to have full control over the installation process and customize the build options according to your requirements.

Step 3. Creating and Using Virtual Environments.

Virtual environments are essential for Python development as they allow you to isolate project dependencies and avoid conflicts between different projects. Each virtual environment has its own Python binary and package installation, ensuring a clean and reproducible development setup.

To create and use virtual environments on Fedora 40, follow these steps:

cd /path/to/your/project

Create a new virtual environment using the venv module:

python3 -m venv myenv

Activate the virtual environment:

source myenv/bin/activate

Install project dependencies using pip:

pip install package_name

Replace package_name with the name of the package you want to install. The package will be installed only within the virtual environment, keeping your system-wide Python installation clean.

When you’re done working on your project, deactivate the virtual environment:


This command will return you to your normal shell environment.

Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing the Python programming language on Fedora 40. system. For additional help or useful information, we recommend you check the Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button