How To Determine Your Python Version on Linux/Ubuntu
Introduction
Figuring out which Python version is installed can be surprisingly tricky sometimes, especially if there’s more than one or if it’s missing altogether. Basically, if you’re running some packages that need a specific Python version, or a script just refuses to work, knowing your current setup is key. This guide walks through how to quickly check what Python you’ve got on Ubuntu, and how to install it if it’s not there yet. It’s kind of weird, but on some machines, Python isn’t installed by default, or it’s an old version. So, better to check first before troubleshooting further.
Step 1: Open the Terminal
This part’s easy. Hit Ctrl + Alt + T to open the Terminal. If that shortcut doesn’t work, you can also search for “Terminal” in your app menu and launch it from there. You’ll need the terminal window ready, because all the magic happens inside it.
Step 2: Check Python 3 Version
Type in python3 --version
and hit Enter. This command is the most common way to see what Python 3 version is installed. Hopefully, it spits out something like Python 3.8.10 or newer. If it does, great! You’re sorted for most projects. On some setups, this works right away, but on others, the command might give an error like “command not found.” That’s a sign Python 3 might not be installed, or it’s a weird configuration.
Step 3: Check Python 2 Version (if you need it)
If you’re doing legacy stuff or some apps still rely on Python 2, check that with python --version
. Normally, you press Enter after typing it. If you see something like Python 2.7.17, then you’ve got Python 2 installed. Many modern Ubuntu versions don’t include Python 2 by default anymore, so don’t be surprised if that just gives you an error.
Step 4: Installing Python 3 if it’s missing
So, if the command from step 2 tells you Python isn’t installed, you’ll need to install it yourself. First, update your package list with sudo apt update
. Because of course, Ubuntu has to make it harder than it should. Then, install Python 3 using sudo apt install python3
. You’ll probably need to type your password, so do that and hit Enter. Once it’s done, run python3 --version
again to see if it’s installed correctly. It’s kind of weird, but sometimes the system needs a reboot or terminal restart for all changes to register, so don’t be surprised if the version doesn’t show up immediately the first time.
Why knowing your Python version matters
It’s not just about bragging rights. Knowing whether you’re running Python 2 versus 3 can save you hours of headache when installing libraries or running scripts. Some apps are picky and require a specific version, ‘cause differences between the two can be huge—like syntax errors waiting to happen if you’re running code designed for Python 3 on 2. So, just a little bit of awareness goes a long way.
Extra Tips & Common issues
Some tips if things aren’t working as expected:
- If typing
python3 --version
orpython --version
gives an error, probably no Python installed. Might need to install it. - If you want a quick way to check multiple versions, just run
which python
andwhich python3
— it shows where they live. - If you installed Python but still get command errors, check if the binary is linked correctly or if your PATH includes the right directories. Sometimes, you’ll need to create symbolic links like
sudo ln -s /usr/bin/python3 /usr/bin/python
(but be careful with that, on some systems it can cause проблемы). - For the latest Python, you might need to add deadsnakes PPA or compile from source, but honestly, for most users, sticking with apt is enough.
- For more detailed info, check out the official Python downloads page.
Wrap-up
That’s about it. Checking your Python version on Ubuntu is a simple step that can save a bunch of time troubleshooting later. And if it’s missing, installing it isn’t rocket science — just a couple of commands away. Usually, this process is smooth, but sometimes, weird environment configs or missing links can trip you up. Stay patient and keep that Terminal handy.
Frequently Asked Questions
What if I have both Python 2 and Python 3 installed?
You can see which one is which by running python --version
for Python 2 and python3 --version
for Python 3. They’re often separately maintained, so don’t be surprised if they differ a lot.
Can I remove Python 2 from my system?
In most cases, yes — if you know what you’re doing. Use sudo apt remove python
with caution, because some system tools depend on it. Better check first if you really don’t need it.
How do I update Python 3 on Ubuntu?
Run sudo apt update
and then sudo apt upgrade python3
. For newer versions, you might need to add a PPA or compile manually, but for most folks, the latest Ubuntu packages are enough.