You can use python -V (et al.) to show you the version of Python that the python command resolves to. If that's all you need, you're done. But to see every version of python in your system takes a bit more.

In Ubuntu we can check the resolution with readlink -f $(which python). In default cases in 14.04 this will simply point to /usr/bin/python2.7.

We can chain this in to show the version of that version of Python:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/usr/bin/python2.7: Python 2.7.6

But this is still only telling us what our current python resolution is. If we were in a Virtualenv (a common Python stack management system) python might resolve to a different version:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4

This is real output.

The fact is there could be hundreds of different versions of Python secreted around your system, either on paths that are contextually added, or living under different binary names (like python3).

If we assume that a Python binary is always going to be called python<something> and be a binary file, we can just search the entire system for files that match those criteria:

$ sudo find / -type f -executable -iname 'python*' -exec file -i '{}' \; | awk -F: '/x-executable; charset=binary/ {print $1}' | xargs readlink -f | sort -u | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4
/media/ned/websites/venvold/bin/python: Python 2.7.4
/srv/chroot/precise_i386/usr/bin/python2.7: Python 2.7.3
/srv/chroot/trusty_i386/usr/bin/python2.7: Python 2.7.6
/srv/chroot/trusty_i386/usr/bin/python3.4: Python 3.4.0
/srv/chroot/trusty_i386/usr/bin/python3.4m: Python 3.4.0
/usr/bin/python2.7: Python 2.7.6
/usr/bin/python2.7-dbg: Python 2.7.6
/usr/bin/python3.4: Python 3.4.0
/usr/bin/python3.4dm: Python 3.4.0
/usr/bin/python3.4m: Python 3.4.0
/web/venvold/bin/python: Python 2.7.4

It's obviously a pretty hideous command but this is again real output and it seems to have done a fairly thorough job.

Answer from Oli on askubuntu.com
Top answer
1 of 9
116

You can use python -V (et al.) to show you the version of Python that the python command resolves to. If that's all you need, you're done. But to see every version of python in your system takes a bit more.

In Ubuntu we can check the resolution with readlink -f $(which python). In default cases in 14.04 this will simply point to /usr/bin/python2.7.

We can chain this in to show the version of that version of Python:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/usr/bin/python2.7: Python 2.7.6

But this is still only telling us what our current python resolution is. If we were in a Virtualenv (a common Python stack management system) python might resolve to a different version:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4

This is real output.

The fact is there could be hundreds of different versions of Python secreted around your system, either on paths that are contextually added, or living under different binary names (like python3).

If we assume that a Python binary is always going to be called python<something> and be a binary file, we can just search the entire system for files that match those criteria:

$ sudo find / -type f -executable -iname 'python*' -exec file -i '{}' \; | awk -F: '/x-executable; charset=binary/ {print $1}' | xargs readlink -f | sort -u | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4
/media/ned/websites/venvold/bin/python: Python 2.7.4
/srv/chroot/precise_i386/usr/bin/python2.7: Python 2.7.3
/srv/chroot/trusty_i386/usr/bin/python2.7: Python 2.7.6
/srv/chroot/trusty_i386/usr/bin/python3.4: Python 3.4.0
/srv/chroot/trusty_i386/usr/bin/python3.4m: Python 3.4.0
/usr/bin/python2.7: Python 2.7.6
/usr/bin/python2.7-dbg: Python 2.7.6
/usr/bin/python3.4: Python 3.4.0
/usr/bin/python3.4dm: Python 3.4.0
/usr/bin/python3.4m: Python 3.4.0
/web/venvold/bin/python: Python 2.7.4

It's obviously a pretty hideous command but this is again real output and it seems to have done a fairly thorough job.

2 of 9
68

Type following in the terminal (Ctrl+Alt+T):

python -V

or

python --version

You can find a list of options/parameters for many commands in the terminal by typing the command followed by --help

Example:

python --help

Manual/manpages also available for most of such CLI which can be displayed by man <command> (Ex: man python)

From man python:

COMMAND LINE OPTIONS
        -V ,  --version
              Prints the Python version number of the executable and exits.

There is also python3 installed on many machines, so you can do:

python3 --version

to find out what python 3.x you are running.

🌐
Hackers and Slackers
hackersandslackers.com › multiple-python-versions-ubuntu-20-04
Managing Multiple Versions of Python on Ubuntu 20.04
August 20, 2023 - For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide: https://packaging.python.org/installing/ Sources ======= The package sources are available at: https://github.com/deadsnakes/ Nightly Builds ============== For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa Press [ENTER] to continue or Ctrl-c to cancel adding it. ... To pick up the versions of Python that Deadsnakes makes visible to us, we still need to run a quick update: ... $ apt list | grep python3.10 WARNING: apt does not have a stable CLI interface.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › reference › availability › python
Available Python versions - Ubuntu for Developers
June 4, 2025 - Ubuntu Python 3 (deb) packages:,,, Ubuntu version, available Python 3 versions, python3-defaults version,,, 25.10 (Questing Quokka), 3.13, 3.14, 3.13,, 25.04 (Plucky Puffin), 3.13, 3.13,, 24.10 (Or...
🌐
CyberITHub
cyberithub.com › how-to-check-all-the-python-versions-installed-on-linux
How to Check all the Python Versions Installed on Linux | CyberITHub
January 11, 2023 - If this utility is available in your system then you need to simply run compgen -c python | grep -P '^python\d' command to list out all the versions of python installed in the system. cyberithub@ubuntu:~$ compgen -c python | grep -P '^python\d' ...
🌐
Finxter
blog.finxter.com › check-ubuntu-python-version
Check Ubuntu Python Version – Be on the Right Side of Change
To see all installed Python versions on Ubuntu, you can use the command apt list --installed | grep python. This will display a list of all Python-related packages installed on your system, including different Python versions.
🌐
Hackers and Slackers
hackersandslackers.com › multiple-versions-python-ubuntu
Managing Multiple Versions of Python on Ubuntu 18.04
August 20, 2023 - The latest version of Python can always be found on the Python Source Releases page on Python.org: ... The first link on the above page should read Latest Python 3 Release - Python 3.X. On that page, scroll to the "files" section and copy the URL of the Gzipped source tarball. On your Ubuntu machine, you're going to fetch the Python source from the URL you copied with wget.
🌐
Softhints
softhints.com › ubuntu-how-to-install-latest-python-and-list-all-python-versions
Ubuntu 18 how to install latest python 3.7 and list all python versions - Softhints
February 1, 2024 - As you can see from both results we get python 2.7 and 3.5. The latest version of python 3 is 3.7 so if you want to installed it you can check next section. For more information about python 3.7 check here: Python 3.7 new features · There are ...
Find elsewhere
🌐
LinuxConfig
linuxconfig.org › home › how to check python version on ubuntu 26.04
How to Check Python Version on Ubuntu 26.04
January 29, 2026 - This command lists all Python-related executables, showing you which versions are available and how the symbolic links are configured. If you need to work with Python 2 for legacy projects, refer to our guide on how to use Python 2 on Ubuntu 26.04.
🌐
Quora
quora.com › How-do-you-check-if-Python-is-installed-in-Ubuntu
How to check if Python is installed in Ubuntu - Quora
Internally in your script, you can use sys.version_info: [code]$ python3 Python 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.
🌐
Finxter
blog.finxter.com › how-to-check-your-python-version
Check Python Version: A Simple Illustrated Guide – Be on the Right Side of Change
The shorter command conda list ... the optional flag ‐‐envs to see all your environments. To check your Python version, run python -V or python ‐‐version in your terminal....
🌐
Launchpad
launchpad.net › ~deadsnakes › +archive › ubuntu › ppa
New Python Versions : “deadsnakes” team
- Ubuntu 22.04 (jammy) Python3.7 - Python3.9, Python3.11 - Python3.13 - Ubuntu 24.04 (noble) Python3.7 - Python3.11, Python3.13 - Note: Python 3.10 (jammy), Python3.12 (noble) are not provided by deadsnakes as upstream ubuntu provides those packages.
🌐
LinuxConfig
linuxconfig.org › home › check python version
Check Python Version: Command & Script Methods
May 3, 2018 - You system may have both Python 2 and Python 3 version installed. List installed python binary executable to see what version is installed on your system:
🌐
How to Use Linux
howtouselinux.com › home › 3 ways to check python version in linux
3 Ways to Check Python Version in Linux - howtouselinux
October 9, 2025 - To check Python version in Linux, you can use python -V command. All you need is to open the terminal then type python -V in the prompt. The Python version will be listed.
Top answer
1 of 5
21

Changing the default Python (or Perl, etc) on an OS is really bad idea. This interpreter is actually part of the OS and there may well be other OS components that are written specifically to work with that version of the interpreter.

For example on Redhat the yum tool that performs system software updates is a python application. You really don't want to break this. Such applications may depend on specific, perhaps non standard, python modules being installed which the version you installed may not have. For example on Ubuntu I believe some of the built-in OS tools written in Python use an ORM called Storm that isn't part of the Python standard library. Does your clean Python 2.7 install have the specific expected version of the Storm module installed? Does it have any version of Storm? No? Then you've just broken a chunk of your OS.

The right way to do this is install your preferred version of python and set up your user account to use it by setting up your .bash_profile, path and such. You might also want to look into the virtualenv module for Python.

2 of 5
13

pyenv

https://github.com/pyenv/pyenv

Pyenv allows you to manage multiple Python versions without sudo for a single user, much like Node.js NVM and Ruby RVM.

Install Pyenv:

curl https://pyenv.run | bash

Then add to your .bashrc:

export PATH="${HOME}/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Find Python version to install:

pyenv install --list

Install the python version you want:

# Increase the chances that the build will have all dependencies.
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
sudo apt build-dep python3
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
  libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
  xz-utils tk-dev libffi-dev liblzma-dev python-openssl git

# Build and install a Python version from source.
pyenv install 3.8.0

List available Python versions:

pyenv versions

We now have:

* system (set by /home/cirsan01/.pyenv/version)
  3.8.0

Select a different python version for the current shell session:

pyenv global 3.8.0
python --version
python3 --version

Both output:

Python 3.8.0

We can now proceed to install and use packages normally:

pip install cowsay
python -c 'import cowsay; cowsay.tux("Python is fun")'
cowsay 'hello'

We can confirm that everything is locally installed in our clean environemnt with:

python -c 'import cowsay; print(cowsay.__file__)'
which cowsay

Per project usage

In the previous section, we saw how to use pyenv in a global setup.

However, what you usually want is to set a specific python and package version on a per-project basis. This is how to do it.

First install your desired Python version as before.

Then, from inside your project directory, set the desired python version with:

pyenv local 3.8.0

which creates a file .python-version containing the version string.

And now let's install a package locally just for our project: TODO: there is no nice way it seems: https://stackoverflow.com/questions/30407446/pyenv-choose-virtualenv-directory/59267972#59267972

Now, when someone wants to use your project, they will do:

pyenv local

which sets the Python version to the correct one.

Tested on Ubuntu 18.04, pyenv 1.2.15.

Conda

I'm not a huge fan of conda's bloatedness, but for better or worse it has become a popular way to manage Python versions and prebuilt shared libraries.

Install miniconda on Linux with:

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm ~/miniconda3/miniconda.sh

and add this to your .bashrc:

PATH="$PATH:$HOME/miniconda3/bin"

then to create a new environment for a project with a specific Python version:

conda create -y -n mytest3.9 python=3.9

and then for each shell where you want to use it in:

eval "$(command conda 'shell.bash' 'hook' 2> /dev/null)"
conda activate mytest3.9

then:

python --version

gives:

Python 3.9.21

and:

which python

gives:

/home/ciro/miniconda3/envs/mytest3.9/bin/python

It also ships its own pip:

which pip

giving:

/home/ciro/miniconda3/envs/mytest3.9/bin/pip

from which you can pip install as in a virtualenv.

You can also let conda modify your .bashrc automatically for you with:

conda init

but unfortunately the code it adds automatically puts you into Conda on every shell which I don't like, so I prefer to do the eval manually per shell as mentioned at: https://stackoverflow.com/questions/55507519/python-activate-conda-env-through-shell-script

Tested on conda 25.1.1, Ubuntu 24.10.

Related threads

  • https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get
  • https://stackoverflow.com/questions/10960805/apt-get-install-for-different-python-versions/59268046#59268046
🌐
Real Python
realpython.com › intro-to-pyenv
Managing Multiple Python Versions With pyenv – Real Python
September 1, 2025 - It includes other Python flavors, such as ActivePython, IronPython, and Jython, as well as distributions like Anaconda. Note: If you’ve been using pyenv for a while and don’t see the version you’re looking for, then you may need to run pyenv update to update the tool and ensure you have access to the latest versions. To see only the available CPython versions starting from 3.10, run the following command: ... $ pyenv install --list | grep -E ' 3\.([1-9][0-9]+)' 3.10.0 3.10-dev 3.10.1 ...
🌐
Note.nkmk.me
note.nkmk.me › home › python
Check Python Version on Command Line and in Scripts | note.nkmk.me
April 23, 2025 - This article explains how to check, get, and print the installed Python version and the one currently used to run scripts on Windows, macOS, and Linux. Check the Python version on the command line: -- ...
🌐
CyberPanel
cyberpanel.net › blog › how-to-check-python-version
Quick Ways to Check Python Version on Mac, Windows & Linux
September 23, 2025 - To make it easier for you if you ... Python Versions: You can know which versions are available by using the command Pyenv versions....