The ps command is used to display information about the processes that are currently running on your Linux terminal. It is the short form of Process Status, which is quite good at explaining what it does. The ps command is also required as a dependency for many programs, and is one of the most common commands found in a UNIX system, like Linux.
However, if your system doesn’t have the command installed, then you’d not be able to run it. It usually comes shipped in most Linux distributions, but there are a few exceptions. For example, trimmed down versions and distributions of Linux usually tend to decrease as many programs and utilities as possible to make the OS small and compatible with old hardware, in which case, it is possible that a particular distribution you’re using has the ps command removed from it. There are other cases such as trying to run the command inside a Docker environment, where you’re more likely to not find the command.
This article will help you get your way round the inability to execute the ps command in your machine. If you prefer, there are many alternatives to this command as well, which we’ll talk about later in the article.
Install ps command in Linux
The easiest way to fix the ps command not found error is by installing the package in your machine which contains the ps command. Now the thing here is that ps is not a standalone utility that you can directly find and install by searching “ps”. Instead, what you need to look for is the procps-ng or the procps package. These packages contain small sized utilities that are very very common UNIX machines, two of which are the kill and ps commands. Therefore, by installing one of these packages, you’ll be able to execute the ps command, if you’re unable to.
To install the package in your system, you’ll need to use your distribution’s package manager. Now different distributions have different package managers, as well as some have their own repository of applications. Using the package manager, you first need to update your system, to refresh the repositories so that the package manager can find the program you’re looking for. Afterwards, you can install the procps package. Some of the commands required to install the package in popular distributions are being listed below:
$ sudo pacman -Syu $ sudo pacman -S procps-ng
$ sudo apt-get update $ sudo apt-get install procps
$ sudo yum makecache $ sudo yum install procps
$ sudo dnf makecache $ sudo dnf install procps
In the above commands, the first line updates your system, and the second line installs the command. If you’ve properly been able to install the package, you should now be able to execute the ps command in your Linux machine.
If for some reason, you’re unable to find the package, or the installation wasn’t successful, you can try to install it from the source code, which will be discussed in the next section of the article.
Install ps command from source
This method of installing the command is not advised, and is best to avoid until necessary as this is probably a bit more problematic for Linux beginners. The package seems to be unmaintained, so there can be issues with stability. If you know complete control of how to install packages from source, or at least the basics to get you running, then you can try it this way.
First, you need to make sure that you have the git package as well as the make package in your Linux machines. Once you’re made that sure, run the following command in your terminal to fetch the source code from the procps repository in Gitlab:
$ git clone https://gitlab.com/procps-ng/procps.git
Now enter the procps directory that you fetched by running:
$ cd procps
Run the autogen.sh script to create the configuration files of the package, by using:
Afterwards, run the configure script this time to prepare the package for building:
Run make to compile the package:
Finally, install the procps command to make the utilities that ship with procps available system wide:
$ sudo make install
You should then be able to execute the ps command, without any further issues.
However, it is also possible that for some reason, the directory where commands like ps is installed is not included in the global PATH variable of your machine. If it is not set, then bourne again shell will not scan that directory when it starts, which essentially means that even if you have the command installed, you’d be unable to run this.
So to fix, this, you need to add one line in the .bashrc file which should be located in your home directory, hidden. First enter this file by using a terminal text editor like nano, by using:
$ nano ~/.bashrc
Inside this .bashrc file, append the following line:
Save and then exit the file. You should now be able to run the command with no further issues.
Alternatives to ps command
There are a whole bunch of other commands that’re similar to the ps command, and in most cases, are superior to it and have more, countless features. My favorite among all is the HTOP utility in Linux.
It is by far, the most popular process listing and management utility that you can find in a linux machine. In fact, it has gotten so popular there are users who know this utility better than the ps command itself. It is heavily customizable and has a bunch of features you’d get old trying out all! Ok enough baffling! Time to know about a few others!
There’s another common competitor to the htop utility, called btop. It has a nicer looking UI as compared to HTOP, but is a bit behind in terms of features and overall popularity. Most of these forks actually come from the same predecessor, the top command, which is also commonly available in most linux distributions like the ps command and comes pre-installed.
These alternatives are targeted to be more interactive as command to the ps command, thus instead of typing out long commands to kill, capture or analyze running processes, you can simply navigate through the processes and run commands on them by simply using arrow keys, the Enter and Esc keys, which is also far more convenient, given that you’re just starting out in Linux.
Despite all, if all you want is to simply list the processes along with their PIDs, the ps command is surely a tough bet!
I’m confident that you won’t need to face any further problems with the error message ps command not found. If you’re just starting out, learning commands like these are quite essential as Linux will reward you with its goods for getting the hang of using the terminal. This is essential because for productive tasks, there is nothing that beats a terminal, and using commands instead of clicking buttons. Don’t you agree?