Install Python


On new Ubuntu servers, Python 3.10 is installed by default. But if you want to install a specific version of Python, this post shows you how.

Run the following commands with sudo or root user.

Install the prerequisites

sudo apt-get update
sudo apt install software-properties-common

Update the sources

sudo add-apt-repository ppa:deadsnakes/ppa

When prompted press Enter to continue:

Press [ENTER] to continue or Ctrl-c to cancel adding it.

Install Python 3.8

sudo apt-get -y install python3.8  # or any other version

Verify the installation

python3.8 --version

Cheers! At this point, Python 3.8 is installed on your Ubuntu system, and you can start using it.

Notes:

  • Installing python3.8 via deadsnakes has an issue with distutils module.

  • While running pip install you might get an error like this:

    from distutils.cmd import Command as DistutilsCommand
    ModuleNotFoundError: No module named 'distutils.cmd'
    
  • To fix this, you can install python3.8-distutils package:

    sudo apt-get -y install python3.8-distutils
    

Hi! If you made it this far, maybe you want to stay in touch. You can follow me on Twitter, subscribe via Atom/RSS.

© Sumit Singh 2023. Content is licensed CC BY-SA 4.0, a Free Culture License. The source code is available under GPLv3. If you see any issue or any typo please create an issue here.

This site's design is heavily inspired by Miles Land. Due to its minimalistic design, it's a great starting point for a personal website.