Python comes pre-installed on most Ubuntu systems, but you may need a newer version or a fresh setup
Ubuntu includes Python 3 by default, but the version bundled with your system may be older than what you need for a specific project. You can check what you have, install a newer version, or set up multiple Python versions side by side. The process takes a few minutes and uses Ubuntu's package manager, which handles downloading and installation automatically.
This guide covers checking your current Python version, installing the latest version from Ubuntu's repositories, and managing multiple versions if you need them. All commands run in the terminal — the same tool you would use for any other system administration task on Ubuntu.
Key Takeaways
- Check your current Python version by typing python3 --version in the terminal; most Ubuntu systems have Python 3 already installed.
- Update to the latest Python version in Ubuntu's repositories by running sudo apt update followed by sudo apt install python3.
- Install development tools needed for some Python packages by running sudo apt install python3-dev python3-pip after the main installation.
- Use update-alternatives to switch between multiple Python versions if you have installed more than one.
Check what version of Python you already have
Open a terminal and type the following command:
python3 --version
The terminal will display the version number — for example, Python 3.10.12. If the command returns "command not found", Python 3 is not installed, and you should proceed to the next section. If you see a version number, you can decide whether to upgrade or keep what you have.
You can also check which Python executable the system is using by typing which python3. This shows the file path, usually /usr/bin/python3. This matters if you have installed Python in multiple locations and need to know which one runs by default.
Update your package list and install Python 3
Ubuntu's package manager, apt, downloads and installs software from Ubuntu's repositories. Before installing anything new, update the list of available packages:
sudo apt update
This command requires your password because it uses sudo, which gives you administrator privileges. Type your password when prompted — the cursor will not move as you type, which is normal.
Once the update finishes, install Python 3:
sudo apt install python3
The system will show you how much disk space the installation will use and ask you to confirm by typing y and pressing Enter. Installation usually takes less than a minute on a broadband connection. When it finishes, verify the installation by running python3 --version again.
Install pip and development tools for Python packages
pip is Python's package manager — it downloads and installs libraries and tools that other people have written. Many Python projects depend on pip to work. Install it alongside Python:
sudo apt install python3-pip
You should also install python3-dev, which includes header files and libraries that some Python packages need to compile correctly:
sudo apt install python3-dev
You can combine both commands into one line:
sudo apt install python3-pip python3-dev
After installation, verify pip works by typing pip3 --version. The output should show a version number and the Python version it is tied to.
Install a specific Python version from Ubuntu's repositories
Ubuntu's repositories usually contain the current stable Python version and sometimes one or two older versions. To see what versions are available, type:
apt search python3 | grep "^python3\."
This shows packages like python3.11 or python3.12. You can install a specific version by name:
sudo apt install python3.12
This installs Python 3.12 alongside your existing Python 3 installation — it does not replace it. Both versions coexist, and you can run either one by typing python3.12 or python3 in the terminal. The python3 command still points to the original version unless you change the default, which is covered in the next section.
Switch between multiple Python versions using update-alternatives
If you have installed more than one Python version and want to change which one runs when you type python3, use the update-alternatives command. First, register each version you have installed:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2
The number at the end (1, 2) is the priority — higher numbers are preferred. Now type:
sudo update-alternatives --config python3
The terminal will show a menu with your installed versions. Type the number next to the version you want to use as the default, then press Enter. From now on, python3 will run that version. You can still run other versions by typing their full name, like python3.10.
Frequently Asked Questions
Do I need to uninstall the old Python version before installing a new one?
No. Multiple Python versions can coexist on the same system without conflict. You can keep the original version and install a newer one, then choose which one to use as the default. This is useful if some of your projects need an older version and others need a newer one.
What is the difference between python3 and python?
On modern Ubuntu systems, python3 is the standard command. The python command (without the 3) may not exist or may point to Python 2, which is no longer supported. Always use python3 unless you have a specific reason to use Python 2.
Why do some packages fail to install with pip?
Some Python packages need to compile code during installation, which requires the development headers and a C compiler. Installing python3-dev and build-essential (type sudo apt install build-essential) solves most compilation errors.
Can I install Python from the official Python website instead of Ubuntu's repositories?
Yes, but Ubuntu's repositories are simpler and keep Python updated automatically with security patches. Installing from the official website gives you more control over the exact version but requires manual updates. For most users, the repository version is the better choice.