Rpm command not found что делать
Linux Command Not Found: This Will Fix It
Are you using Linux and you have seen the “Command Not Found” error while trying to execute a command? It’s time to find out why.
We will look at this error together and understand how to fix it.
What is the cause of the command not found error?
The “Command not found” error is caused by the fact that Linux is unable to find on your system a command you try to execute. When you run a command Linux looks for binaries in the list of directories specified in the PATH environment variable, this allows you to execute a command without specifying its full path.
In this article we will go through an example of this error and I will show you how to fix it.
You will also understand how Linux (or Unix-like systems) look for commands when a user executes them.
The PATH Environment Variable
Linux system are configured with a pre-defined set of environment variables required by the operating system to function properly.
The PATH environment variable is one of the most important environment variables in a Linux system. It contains a list of directories used by Linux to search for commands that can be executed without specifying their full path.
You can use the echo command to see the value of the PATH variable:
In the list of directories inside the PATH you can see the home directory for my current user (ec2-user) but also directories like /usr/bin.
Let’s have a look at some of the commands present in the /usr/bin directory. To restrict the list of commands returned by ls, I just look for commands starting with ch (I use the ch* wildcard to do that):
Let’s take the chmod command as an example.
If I use the which command to check the full path of the chmod command I get the following:
As you can see this is exactly the same directory in the PATH, /usr/bin.
The fact that /usr/bin/ is in the PATH allows us to execute the chmod command withouth having to specify its full path.
Where Is PATH Defined in Linux?
Wondering where is the PATH environment variable defined?
It’s usually defined somewhere in your home directory, and specifically in one of the hidden files used in Linux to configure your user environment: the .bashrc file.
As you can see the PATH variable is defined and it’s then made available to any child processes of this shell using the export command.
This is a common requirement if you download external tools that are not part of the Linux operating system and you want to be able to execute them from your shell without having to specify their full path.
One common scenario is adding Java to the Linux PATH after downloading the JDK (Java Development Kit) on your system.
PATH Configured At System-Wide Level
When I see the value of the PATH variable on my system, here’s what I get:
There’s something that doesn’t make sense to me…
They must be defined somewhere at system level and not just at user level.
In Linux, system-wide configuration files are located under the /etc directory. For example in /etc/bashrc.
Let’s find out where this initial value for the PATH comes from using a recursive grep as root under the /etc directory.
The only result is in the configuration file for the SSH deamon. According to a comment in this file, the daemon is compiled with the PATH set to the value I’m seeing on my system.
That’s where the value of the PATH comes from!
How Do I fix the Bash error “command not found”?
So far we have seen what the PATH is…
…but how does it help us fix the command not found error?
First of all, before looking at how the command not found error could be related to the PATH, let’s look at a simple cause.
Before doing any other checks make sure you are not misspelling the command when you execute it.
This might be happening mostly to those who are new to Linux and are learning the commands.
If the way you have typed the command is correct, then keep going…
Scenario 1 can occur if you download a specific tool on your Linux system and you don’t add the directory in which the binary is located to the PATH environment variable.
Let’s say the current value of the PATH is:
And I want to add the directory /opt/install to it because that’s where the command I want to execute is located. That line would become:
The order of the directories in the PATH is important, the first directory has higher priority than the second directory, and so on.
So, if you want the /opt/install directory to be the first one to be searched when a command is executed the PATH definition becomes:
In the next section we will look at the scenario 2, where the command is not available on your Linux system.
Running a Command Not Available on the System
Now, let’s have a look at what happens when we execute a command that is not available on a Linux system.
I take, for example, the rsync command:
How do I know if I’m seeing the “command not found” error because the rsync command is not in the PATH or because it doesn’t exist on the system at all?
I can use the package manager of my Linux distribution. In this case I’m using CentOS and hence I will use the yum command to see if the rsync package is installed:
This command doesn’t return any results, this means rsync is not available on the system.
Another option is to use the RPM command to query the RPMs installed on my Linux system:
Once again, no results for the rsync package.
So, let’s install it!
The yum search command returns a result for rsync:
And we can install the rsync package using the “yum install” command:
And now if I try to execute the rsync command again to check its version:
The command works well!
Conclusion
I have also explained how the PATH environment variable works and how important is for a Linux system.
Have you managed to find what’s causing this error in your system?