How to Install Python 3 on Ubuntu (Quick Setup)
In this tutorial, you'll learn about How to Install Python 3 on Ubuntu (Quick Setup). We cover key concepts, practical examples, and best practices.
The Problem
You need Python 3 on Ubuntu but python returns nothing or points to Python 2.
Why this happens
Ubuntu stopped including Python 2 by default several releases ago, and even Python 3 may not be installed on minimal or Docker-based systems. The python command without a version suffix is also not always mapped — Ubuntu provides python3 by default and leaves python unlinked. This means scripts expecting python will fail until you either install python-is-python3 or adjust your shebang lines.
Which approach should you use?
If you just need Python for system scripts, use apt. If you need a specific version for a project, use the deadsnakes PPA. If you work on multiple projects with different version requirements, use pyenv. This guide covers all three so you can pick the one that fits your situation.
Quick Fix
Ubuntu 24.04+ (Python 3.12)
sudo apt update
sudo apt install python3 python3-pip python3-venv
Ubuntu 22.04 LTS (Python 3.10)
sudo apt update
sudo apt install python3 python3-pip python3-venv
Ubuntu 20.04 LTS (Python 3.8)
Same commands — it installs the default version for your release.
The commands are identical across Ubuntu versions because apt always pulls the Python version that ships with your specific release. Ubuntu 24.04 includes Python 3.12, 22.04 has 3.10, and 20.04 has 3.8. The python3-venv package is important — it adds the venv module that lets you create isolated Python environments. Without it, python3 -m venv will fail.
Verify the installation
python3 --version
pip3 --version
Expected output:
Python 3.12.3
pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)
If you see a version number, Python is ready. If you get "command not found", the packages may not have installed correctly — run sudo apt install --reinstall python3 to retry.
Use python Instead of python3
sudo apt install python-is-python3
Now python uses Python 3.
This creates a symlink from /usr/bin/python to /usr/bin/python3. If you use pyenv, this package is not needed — pyenv manages the python command itself.
Install a Specific Python Version
Use the deadsnakes PPA for non-default versions:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11 python3.11-venv python3.11-distutils
The deadsnakes PPA is maintained by the Ubuntu community and provides every recent Python version for every Ubuntu release. This is useful when your project requires Python 3.11 but you are on Ubuntu 24.04 which ships Python 3.12. After installing, use python3.11 to run that specific version. The distutils package is needed for installing packages from source with older Python versions.
Using pyenv (Best for Multiple Versions)
curl https://pyenv.run | bash
pyenv install 3.12.3
pyenv global 3.12.3
pyenv lets you install and switch between any Python version without affecting the system installation. After running the install script, add the pyenv initialization lines to your shell config file (~/.bashrc or ~/.zshrc) as instructed by the installer. You can then set a global default, a per-project version via .python-version, or a per-shell version with pyenv shell. This is the recommended approach for developers who work on multiple projects with different Python version requirements.
Prevention
Avoid installing Python globally for every project. System-wide Python installations become hard to manage when you have multiple projects. Use virtual environments (python3 -m venv) or pyenv to isolate dependencies.
Do not remove the system Python. Ubuntu relies on Python for internal tools like apt and software-properties-common. Removing or replacing the system Python can break your operating system.
Always install python3-venv alongside Python. This package is not always included by default, and you will need it for creating virtual environments. Without it, common workflows like python3 -m venv myenv will fail with an error.
Pin your Python version in CI and production. Use a .python-version file (supported by pyenv) or specify the version in your Dockerfile. This prevents unexpected breakage when a new Python release changes behavior.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro