How To Properly Update Python on Linux/Ubuntu
Updating Python on Ubuntu isn’t always as smooth as clicking update in a GUI — especially because Ubuntu tends to hang onto its default Python version for stability reasons. If you’re into newer features, security patches, or just tired of running that outdated Python version, this guide should help you get the latest one installed without breaking everything. Usually, it’s about adding a trusted repo, hitting a few commands, and voilà — new Python in the house. Not sure why, but sometimes you’ll follow these steps and it still refuses to update properly, which can be kinda frustrating. But hey, persistence pays off.
How to Update Python on Ubuntu
Adding the right repository to get newer Python versions
Ubuntu’s default repositories tend to lag behind the latest Python releases. To get the newest stable version, adding the deadsnakes PPA is usually the way to go. It’s trusted, popular, and has a lot of recent Python builds. On some setups, you might get a warning that the PPA is insecure or something — just double-check you’re on the official site and not a scam. Once added, your system will be more receptive to newer Python releases.
Step-by-step to install the newer Python
- Open the terminal. Usually Ctrl + Alt + T. Because of course, Ubuntu has to make it unnecessarily tricky sometimes.
- Check your current Python version — in the terminal, type:
python3 --version
. This gives you a baseline before messing with anything. - Add the deadsnakes repo. Run:
sudo add-apt-repository ppa:deadsnakes/ppa
. When prompted, press Enter. Sometimes it takes a couple seconds for the repository to be added, especially if your internet isn’t the fastest. - Update your package list. Hit:
sudo apt update
. This tells your system to pull latest package info, including the new Python builds. - Install the latest Python version. Say you want Python 3.12, run:
sudo apt install python3.12
. If you want to make sure you’re installing the version you want, check the exact package name — sometimes it’s just python3.x. - Verify the installation. Run:
python3 --version
again. If all went well, it’ll show Python 3.12 (or whatever’s latest). If not, it might be that your default still points to the older version.
Making the new Python version the default in your terminal (optional but recommended)
This part trips a lot of people up, because Ubuntu’s default is stuck on the older version for stability. To switch it over, use update-alternatives. Run:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
Then, check what options are available:
sudo update-alternatives --config python3
This will let you pick your preferred version, just like switching default browsers or editors. Not all systems will switch seamlessly, so expect some fiddling if things get weird — especially if some system process relies on a specific Python version.
Extra tips & common hiccups
- Always back up any projects or virtual environments before upgrading Python. Things can break unexpectedly.
- If things seem stuck, double-check that the deadsnakes repo is really added by inspecting /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa.list.
- Using virtual environments (venv) helps prevent conflicts if multiple Python versions coexist; just a good idea in general.
- Sometimes, pip might get muddy after the update. Make sure you’re installing packages with the new Python version’s pip (like
python3.12 -m pip install package_name
) to avoid confusion.
Wrap-up
Getting the latest Python on Ubuntu isn’t unicorn magic, but it’s also not perfectly slick. Adding the deadsnakes repo, updating, and installing the version you want usually does the trick — if you’re patient and careful. Just keep in mind your system might still use the older Python by default unless you switch it over, but overall, this should keep you a lot more up-to-date than the standard repos allow.
Frequently Asked Questions
Why bother updating Python?
Because sometimes you need those shiny new features, or security patches, or maybe just the ability to run newer libraries. Old Python versions can be a pain in the long run.
What if the update still doesn’t seem to work?
Ideally, double-check you added the right repo and ran sudo apt update
. Also, make sure to verify what’s installed with python3 --version
— sometimes your system defaults to an old version even after install. In that case, look into update-alternatives.
Can I install multiple versions at once?
Heck yes. Just remember to use virtual environments or specify the full Python binary path when running scripts. Mixing them up can lead to some headaches if you’re not careful.