Troubleshooting "Command Not Found" Error in Shell

Why does the shell complains that the command couldn't be found?

What shell variable should be checked in this situation?

Answer:

If a command in /usr/local/bin can't be found, the shell variable PATH may be improperly configured.

When you encounter the error message "command not found" in the shell, it indicates that the shell is unable to locate the command you are trying to run. This usually happens when the command is placed in a directory that is not included in the PATH variable.

The PATH variable is a shell environment variable that contains a list of directories where executable files are located. When you type a command in the shell, the system searches through these directories in the order they are specified in the PATH variable to find the executable file.

To troubleshoot the "command not found" error, you should check the value of the PATH variable. If the directory containing the command is not included in the PATH, you need to add it.

You can view the current value of the PATH variable by typing the command echo $PATH in the shell. If the directory /usr/local/bin is missing from the output, you can add it to the PATH variable either temporarily or permanently.

To add /usr/local/bin to the PATH temporarily, you can use the command export PATH=$PATH:/usr/local/bin. This will append the /usr/local/bin directory to the existing PATH variable for the current shell session.

If you want to make this change permanent so that /usr/local/bin is always included in the PATH, you can add the above command to your shell's initialization file. The initialization file varies depending on the shell you are using, such as .bashrc, .bash_profile, or .profile.

← Offset bending determining distance between bends The exciting impact of new technology on sustainability →