Python 3.10 Installation on the Ubuntu

To install Python 3.10 on your Ubuntu system, you can follow these steps. Please note that the specific commands and package names may vary depending on your Ubuntu version and distribution.

  1. Update Package List:

    Open a terminal and ensure your package list is up to date by running:

     sudo apt update
    
  2. Install Prerequisites:

    Install some packages that are necessary for building Python from source:

     sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
    
  3. Download Python 3.10:

    You can download Python 3.10 from the official Python website or use wget to download it directly. Here, we will use wget:

     wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
    
  4. Extract the Archive:

    Extract the downloaded Python source code:

     tar -xf Python-3.10.0.tar.xz
    
  5. Build and Install Python 3.10:

    Navigate to the Python source directory and run the following commands to build and install Python:

     cd Python-3.10.0
     ./configure --enable-optimizations
     make -j$(nproc)
     sudo make altinstall
    

    The --enable-optimizations flag is recommended to enable additional optimizations during the build process.

  6. Verify Python Installation:

    You can verify that Python 3.10 is installed correctly by running:

     python3.10 --version
    

    This should display the Python version as "Python 3.10.0."

Python 3.10 is now installed on your system. You can use it by running scripts with the python3.10 command. Keep in mind that system packages that rely on Python may still use an older version of Python, so use python3.10 explicitly when you want to run scripts with this specific version.

Remember that these instructions are for Ubuntu, and the package names and commands may vary for other Linux distributions.


Lets set the Python to default

If you're unable to run python --version and it says "not found," it likely means that the python command is not set as an alias to Python 3.10. To set up this alias, follow these steps:

  1. Check Python Version:

    Verify the installed Python version and its binary name by running:

     python3.10 --version
    

    This command should display the Python version as "Python 3.10.0" or similar.

  2. Create a Symbolic Link:

    To set the python command as an alias for Python 3.10, you can create a symbolic link. Run the following command:

     sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
    

    This command creates a symbolic link in the /usr/bin directory, making the python command point to Python 3.10.

  3. Verify the Alias:

    You can now verify that the python command is set to Python 3.10 by running:

     python --version
    

    This command should display the Python version as "Python 3.10.0" or similar.

With these steps, you should have python aliased to Python 3.10, and you can use the python command to run Python 3.10 scripts. If you have other Python versions installed on your system, you can still use python3.10 to explicitly specify Python 3.10 when needed.

0
Subscribe to my newsletter

Read articles from Srikanth Pentapati directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Srikanth Pentapati
Srikanth Pentapati