VMware ESXi and vSphere Cluster Management
How to Install and Verify Python on Linux
Learn how to check Python on Linux and install Python 3 on Debian, Ubuntu, SUSE, and other distributions using the correct package manager.
Python is a programming language and runtime that is included by default on many Linux distributions. The installed version and command name can vary, so the safest first step is to check which Python executable is available.
For new development, use Python 3. Python 2 is an obsolete major version that may still exist on older systems for compatibility, but it should not be selected for new projects.
Open a Linux terminal
A terminal is a text-based interface for entering commands. The shell inside the terminal interprets those commands and displays their results.
Open your desktop's terminal application, then type a command at the prompt and press Enter. For example:
python3 --versionIf Python 3 is available, the terminal prints a version number, such as:
Python 3.12.3The exact version depends on your Linux distribution and its repositories.
Check whether Python is installed
Preferred check: Python 3
Run:
python3 --versionSuccessful output begins with Python 3 and includes the major, minor, and patch version numbers. This command is preferred because it explicitly requests the Python 3 executable.
Check the generic python command
You can also run:
python --versionThe python command is distribution-dependent. It may point to Python 2, point to Python 3, or not exist at all. Compare its result with python3 --version before using it in scripts or instructions.
| Command | Possible output | Meaning | Recommended next action |
|---|---|---|---|
python3 --version | Python 3.x.y | Python 3 is available under its preferred command name. | Use python3 for Python 3 work. |
python --version | Python 3.x.y | The generic command currently points to Python 3. | Use python3 when you need predictable behavior across distributions. |
python --version | Python 2.x.y | The generic command points to legacy Python 2. | Use python3; do not choose Python 2 for new work. |
| Either command | command not found or a similar message | The command is unavailable, Python is not installed under that name, or the executable is not on the shell's PATH. | Install Python 3 with the distribution's supported package manager and check again. |
PATH is an environment variable containing directories where the shell looks for executable commands. A valid installation can still be difficult to run if its executable directory is not on PATH.
Choose the correct installation method
Linux distributions use package managers to install, update, and remove software. The correct command depends on the distribution family. Debian-based systems commonly use APT, while RPM-based systems use tools supplied by their distribution. SUSE provides YaST and also commonly provides the zypper command.
| Distribution family | Examples | Package-management tool | Typical Python package | Verification command |
|---|---|---|---|---|
| Debian-based | Debian, Ubuntu | APT | python3 | python3 --version |
| RPM-based | Fedora, Red Hat-derived distributions | The distribution's RPM package tool | Usually python3, or a supported version-specific package | python3 --version |
| SUSE | openSUSE, SUSE Linux Enterprise | YaST Software Management or zypper | Usually python3, or a supported version-specific package | python3 --version |
Install Python 3 on Debian or Ubuntu
Debian and Ubuntu are Debian-based distributions. Their package manager is APT. Installing system software requires administrative privileges, commonly provided with sudo. The sudo command runs an authorized command with administrator privileges and may request your user password.
1. Refresh package information
Refresh the local package metadata before installing:
sudo apt updateThis downloads current package information from the configured repositories. It does not install Python by itself.
2. Install the Python 3 package
sudo apt install python3Read the package summary, confirm the installation when prompted, and wait for APT to finish.
3. Verify the installation
python3 --versionThe result should report a Python 3 version, for example Python 3.12.x. The minor and patch numbers depend on your distribution release and enabled repositories.
Install Python on RPM-based distributions
RPM is a package format and a distribution family used by systems such as Fedora, Red Hat-derived distributions, and SUSE. These systems do not normally use APT. Use the package-management tool supported by the specific distribution.
Package names can vary. Search for a package named python3 or for a supported, version-specific Python 3 package, then install it with the distribution's normal software tool. After installation, verify it with:
python3 --versionFor Fedora, Red Hat-derived systems, or other RPM-based distributions, consult the distribution's package-management documentation or software manager rather than substituting an APT command.
Install Python on SUSE
SUSE provides YaST, a system administration and software-management tool. You can install Python through YaST's Software Management interface:
- Open YaST and select Software Management.
- Search for an appropriate Python 3 package, commonly named
python3. - Select the package for installation and apply the changes.
- Open a terminal and run
python3 --version.
When command-line package management is available, zypper is another supported SUSE tool. A typical installation command is:
sudo zypper install python3Confirm the package selection if prompted, then verify the result:
python3 --versionChoose the package and command carefully
The python3 package and python3 command are generally preferred because they identify the current Python major version explicitly. Some distributions provide separate packages for particular minor versions, such as a package associated with Python 3.x. Follow the naming used by your distribution's repositories.
Do not remove or replace the Python installation supplied by the operating system merely to change the result of python --version. System utilities may depend on the distribution-provided interpreter. For project-specific versions, use a supported version-specific package or an approved environment-management approach instead of overwriting system files.
Verify the installation after setup
Always run a version check after the package manager finishes:
python3 --versionYou can also launch the interactive Python 3 interpreter as a basic runtime test:
python3A successful launch displays information about Python and then shows an interactive prompt, commonly represented by >>>. Enter a simple expression:
print(