Cyberithub

How to Check all the Python Versions Installed on Linux

Advertisements

In this article, we will see how to check all the python versions installed on a Linux system. Many times you might have noticed that either knowingly or unknowingly you end up installed multiple python versions in your linux system. And some day you only realize this when you started getting certain strange messages on the output pointing different versions of python available in the System. Well, at that point of time you probably would like to know all the python versions installed on your System. While there are many ways to check this but here we will only see four methods that can be used in a linux system to detect all the python versions.

 

How to Check all the Python Versions Installed on Linux 2

How to Check all the Python Versions Installed on Linux

Also Read: How to Install Ansible on Ubuntu 20.04 LTS (Focal Fossa)

Method 1: Using whereis command

The first method you can think of using is through whereis command which is easily available in almost all the linux distributions. So if you are looking for all the versions of python3 then you just need to run whereis python3 command and you will able to see all the python3 versions as shown below. This works great in almost all the linux systems.

cyberithub@ubuntu:~$ whereis python3
python3: /usr/bin/python3 /usr/bin/python3.8 /usr/bin/python3.9 /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /etc/python3.9 /usr/local/lib/python3.8 /usr/local/lib/python3.9 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz

Similarly, if you would like to check all the installed versions of python2 then you need to use whereis python2 command as shown below.

cyberithub@ubuntu:~$ whereis python2
python2: /usr/bin/python2.7 /usr/bin/python2 /usr/lib/python2.7 /etc/python2.7 /usr/local/lib/python2.7 /usr/share/man/man1/python2.1.gz

 

Method 2: Using ls command

The second method that I always love to use is through ls command. This command is also very easily available on almost all the linux distribution. Using this command, you just need to look for all the python binaries available under /usr/bin path to detect all the versions of python currently installed as shown below. You can check more about ls command on 16 Best ls command examples in Linux.

cyberithub@ubuntu:~$ ls -ls /usr/bin/python*
   0 lrwxrwxrwx 1 root root       9 Mar 13  2020 /usr/bin/python2 -> python2.7
3580 -rwxr-xr-x 1 root root 3662032 Jul  1  2022 /usr/bin/python2.7
   0 lrwxrwxrwx 1 root root       9 Nov 15 20:46 /usr/bin/python3 -> python3.8
5368 -rwxr-xr-x 1 root root 5494584 Nov 14 18:29 /usr/bin/python3.8
5668 -rwxr-xr-x 1 root root 5803968 Nov 23  2021 /usr/bin/python3.9
   4 -rwxr-xr-x 1 root root     384 Mar 28  2020 /usr/bin/python3-futurize
   4 -rwxr-xr-x 1 root root     388 Mar 28  2020 /usr/bin/python3-pasteurize

 

Method 3: Using compgen command

Another method that you can think of using is through compgen command. 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'
python3-pasteurize
python2.7
python2
python3
python3.8
python3-futurize
python3.9
python3-pasteurize
python2.7
python2
python3
python3.8
python3-futurize
python3.9

 

Method 4: Using find command

The last method that I would advise to use is through find command. You can search and look for all different python symbolic link under /usr/bin path using find /usr/bin/python* ! -type l command as shown below. You can check more about find command on 40 Best Examples of Find Command in Linux.

cyberithub@ubuntu:~$ find /usr/bin/python* ! -type l
/usr/bin/python2.7
/usr/bin/python3.8
/usr/bin/python3.9
/usr/bin/python3-futurize
/usr/bin/python3-pasteurize

Leave a Comment