How to fix the error – bash: python: command not found error

The error is bash: python: command not found Error showing up mainly for three reasons. First of all, is the python executable installed on the machine? If it is installed, is the PATH environment variable set correctly so that it can find the installed executable? The third reason might be a broken symbolic link.

This article shows you how to fix the error – bash: python: command not found. Let’s see how to fix this problem.

1. Check if Python is installed.

Most of the time this error occurs at a shell prompt or command line because python is not installed or is corrupted. Let’s first check if Python is installed.

Run the following commands to find your installed Python location.

$ which python3


$ type -a python3


python3 is/usr/bin/python3
python3 is/bin/python3


$ ls -l/usr/bin/python
$ ls -l/usr/local/bin

Run the command to check your Python version:

$ python3 --version

Simple python3 run command:

$ python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

If you don’t find python installed, I’ll show you how to install python in the next section.

Install Python on Ubuntu / Debian

Debian, Ubuntu and their derivatives come with python preinstalled. If it is damaged or not installed then use the following command.

To install python 2, enter:

$ sudo apt install python

After January 1, 2020 Python 2 no longer receives any updates, and recommend not using it.


To install python 3, enter:

$ sudo apt install python3

Python is installed from source, by default it is installed to http: // usr / local / bin /. In this case, typing python in the console will not execute the one inside / usr / local / bin /, but the one inside / usr / bin /.

If you want to execute the one inside / usr / local / bin /, you can easily configure the system using an alias. The alias should be placed in the .bashrc file as shown below.

alias python=/usr/local/bin/python3.9

Install Python on Fedora

Thanks to the dnf package manager, you can easily install python on Fedora:

$ sudo dnf установить python38

Install Python on RHEL / CentOS

To install Python on RHEL, Oracle Linux and CentOS, use the yum command as follows:

$ sudo yum установить python

Install Python on Arch Linux

On Arch Linux, run the following command to install python:

$ sudo pacman -S python2

$ sudo pacman -S python3

2. Check your PATH environment variable.

Every time you, as a user, run a command on your console, the machine looks for its location or address in a list of predefined directories stored in the PATH environment variable.

This design helps to run a program or command correctly without having to specify an absolute path in the terminal.

The PATH environment variable can be changed temporarily for the current terminal session, or permanently.

To display the contents of the PATH environment variable to the console:

$ echo $ PATH



Make sure the set Python path is added to your PATH variable. You can see in the above output the paths ‘/ usr / bin’ and ‘/ bin’ for python 3. To make it permanent, be sure to export your PATH variable to ~ / .bash_profile or the appropriate config file that starts the shell.

3. Check the broken symbolic link.

When you run the python script, you may realize that the symlink to the Pythons executables is incorrect.

To change the / usr / bin / python directory to / usr / local / bin / python3.9, enter:

$ sudo ln -s/usr/local/bin/python3.9/usr/bin/python


In this article, we learned how to properly fix the -bash: python: command not found error on your Linux machine.

Please disable your ad blocker or whitelist this site!

Related Posts