Last modified: May 25, 2025 By Alexander Williams
Install Python on Ubuntu in 5 Steps
Python is a popular programming language. Ubuntu often comes with Python pre-installed. This guide shows how to install or update Python on Ubuntu.
Table Of Contents
Check Existing Python Installation
First, check if Python is already installed. Open your terminal and run:
python3 --version
This command shows the installed Python version. Most Ubuntu versions include Python 3 by default.
Update System Packages
Before installing Python, update your package list. Run:
sudo apt update
This ensures you get the latest available packages. Then upgrade existing packages:
sudo apt upgrade
Install Python from Ubuntu Repository
The easiest way to install Python is using Ubuntu's package manager. Run:
sudo apt install python3
This installs the latest stable Python 3 version available in Ubuntu's repositories.
Install pip (Python Package Manager)
pip is essential for managing Python packages. Install it with:
sudo apt install python3-pip
Verify pip installation with:
pip3 --version
For more details on pip, see our guide on How to Install pip for Python.
Install Additional Development Tools
For Python development, install these useful packages:
sudo apt install build-essential python3-dev python3-venv
These include compilers and headers needed for some Python packages.
Create a Virtual Environment
Virtual environments keep projects isolated. Create one with:
python3 -m venv myenv
Learn more about Python Virtual Environments in our detailed guide.
Alternative Installation Methods
Install Multiple Python Versions
Use pyenv to manage multiple Python versions. See our pyenv installation guide.
Install from Source
For the latest Python version, compile from source. Check our Python source installation guide.
Use Miniconda or Anaconda
For data science, consider Miniconda or Anaconda.
Verify Python Installation
Create a simple test script:
# test.py
print("Python is working!")
Run it with:
python3 test.py
You should see:
Python is working!
Conclusion
Installing Python on Ubuntu is simple. The default repository method works for most users. For advanced needs, consider alternative methods.
Now you're ready to start Python development on Ubuntu. Remember to use virtual environments for your projects.