As of today, Python 3.11 is the latest version available for installation. Python developers who want to start creating a new application should use the latest version. This tutorial will help you to install Python 3.11 on Ubuntu systems. In this guide, we will discuss two methods for installing Python on Ubuntu, The first method will install Python using PPA and the second method will compile Python from the source code.

  • You may also like: Creating the Python Virtual Environment for Your Application
  • Prerequisites

    The Python packages and source code installation required the dependencies to be installed on the system. The compilation of source code required multiple build libraries on the system. Execute the following commands to install the required packages on your system.

    sudo apt install build-essential checkinstall  
        libreadline-gplv2-dev  libncursesw5-dev libssl-dev 
        libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev 
    

    Step 1: Install Python on Ubuntu

    Choose one of the below methods to install Python 3.11 on a Ubuntu system. We recommend using the first method, but if in case it is not working, go with the second method.

    Method 1: Installing Python 3.11 using PPA

    The latest Python versions are available under the ~deadsnakes team PPA. You can add this PPA to your Ubuntu system with the following command:

    sudo add-apt-repository ppa:deadsnakes/ppa 
    

    Then you can install Python 3.11 using the apt-get package manager.

    sudo apt install python3.11
    

    This will install Python 3.11 on your Linux system.

    Method 2: Installing Python 3.11 using Source Code

    If the repository doesn’t contain the Python packages for your system, install it by compiling it from the source code.

    1. Download Python 3.11 source code:
    2. Python 3.11.1 version is available for installation. You can visit the Python official websites to check for the latest available version. Use the following commands to download the Python 3.11 source code.

      cd /usr/src 
      sudo wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz 
      
    3. Extract archive:Once the download is finished, extract the archive file content.
      sudo tar xzf Python-3.11.1.tgz 
      
    4. Prepare source code: Now prepare the source code as per your system architecture and environment. Also, use --enable-optimizations option with configure command to enable additional supports like SSL, bz2 support.
      cd Python-3.11.1 
      sudo ./configure --enable-optimizations 
      
    5. Compile and install: After preparing the source code, compile it using the make command. Make use altinstall, to install it as a separate Python. So that this will not overwrite the existing Python installation.
      sudo make altinstall 
      

      make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

    Step 2: Check Python Version

    Finally, you have successfully installed Python 3.11 on your system. Let’s check the version installed of python using the below command.

    python3.11 -V 
    
    Python 3.11.1
    

    Step 3: Installing PIP

    If you have installed Python using the package manager, the PIP will not be installed by default. In that case, you will need to install it manually. To install PIP, execute the following command.

    curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11 
    

    Once the PIP is installed successfully, check its version by executing the command:

    pip3.11 -V 
    
    pip 22.3.1 from /usr/local/lib/python3.11/dist-packages/pip (python 3.11)
    

    Conclusion

    In conclusion, this tutorial helped you to install Python 3.11 on Ubuntu systems. The first method uses the package manager to install Python from PPA. The second method helps you to compile and install Python 3.11 on your Ubuntu systems.