Python is among the most popular programming languages used by developers today. However, over its lifespan, Python has undergone a series of updates leading to multiple versions of Python, including Python 2.x and Python 3.x.
It’s important for developers to know what versions of Python they have installed on their machines to ensure the compatibility and functionality of their scripts. This tutorial is going to walk you through how you can check how many Python versions you have installed on your Linux system.
Step 1: Open the terminal
Your terminal is your main interface with your Linux system. To open it, you can use the keyboard shortcut Ctrl + Alt + T or search for the terminal in your system’s application menu.
Step 2: Check for the Python 2 version
Type the following command into your terminal and hit Enter:
1 |
python --version |
Step 3: Check for the Python 3 version
To check if Python 3 is installed, type the following command:
1 |
python3 --version |
Step 4: Decoding the output
If Python is installed on your system, the terminal will output a version number. For example, Python 2.7.18 or Python 3.8.5. If Python is not installed, it will output a message saying Python: command not found.
Step 5: Checking for additional Python installations
It’s common to have more than one version of Python installed on your system. To check for additional Python 2 installations, you can use the following command:
1 |
ls /usr/bin/python* |
For Python 3, replace python with python3 in the command.
Conclusion
Knowing how to check for different Python versions installed on your Linux machine is vital for code compatibility and functionality.
As a developer, it’s important that you are familiar with your development environment, including which versions of Python you’re working with. Always check to ensure that your code is compatible with your installed Python version(s).