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 --version

If Python 3 is available, the terminal prints a version number, such as:

Python 3.12.3

The exact version depends on your Linux distribution and its repositories.

Check whether Python is installed

Preferred check: Python 3

Run:

python3 --version

Successful 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 --version

The 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.

CommandPossible outputMeaningRecommended next action
python3 --versionPython 3.x.yPython 3 is available under its preferred command name.Use python3 for Python 3 work.
python --versionPython 3.x.yThe generic command currently points to Python 3.Use python3 when you need predictable behavior across distributions.
python --versionPython 2.x.yThe generic command points to legacy Python 2.Use python3; do not choose Python 2 for new work.
Either commandcommand not found or a similar messageThe 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 familyExamplesPackage-management toolTypical Python packageVerification command
Debian-basedDebian, UbuntuAPTpython3python3 --version
RPM-basedFedora, Red Hat-derived distributionsThe distribution's RPM package toolUsually python3, or a supported version-specific packagepython3 --version
SUSEopenSUSE, SUSE Linux EnterpriseYaST Software Management or zypperUsually python3, or a supported version-specific packagepython3 --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 update

This downloads current package information from the configured repositories. It does not install Python by itself.

2. Install the Python 3 package

sudo apt install python3

Read the package summary, confirm the installation when prompted, and wait for APT to finish.

3. Verify the installation

python3 --version

The 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 --version

For 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:

  1. Open YaST and select Software Management.
  2. Search for an appropriate Python 3 package, commonly named python3.
  3. Select the package for installation and apply the changes.
  4. 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 python3

Confirm the package selection if prompted, then verify the result:

python3 --version

Choose 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 --version

You can also launch the interactive Python 3 interpreter as a basic runtime test:

python3

A successful launch displays information about Python and then shows an interactive prompt, commonly represented by >>>. Enter a simple expression:

print(