Fixing ‘ps: command not found’

Why is the 'ps' command not found?

The "ps: command not found" error typically occurs when the command isn't available on your system. This can happen if the 'procps' package isn't installed or if there are PATH issues.

For Debian-based systems like Ubuntu, install it with:

sudo apt-get install procps

For Red Hat-based systems, use:

sudo yum install procps-ng

To check your PATH, run echo $PATH and ensure it includes /bin and /usr/bin. Update if necessary using:

export PATH=$PATH:/bin:/usr/bin

In minimal environments like Alpine Linux, the full 'procps' package might not be included. Install it by running:

apk add procps

after updating with:

apk update

How to install 'ps' on various systems

Debian-based systems (Ubuntu):

  1. Update package index: sudo apt-get update
  2. Install: sudo apt-get install procps

Red Hat-based systems (CentOS, AlmaLinux, Rocky Linux):

  1. Update package manager: sudo yum update
  2. Install: sudo yum install procps-ng

Fedora:

  1. Refresh repository data: sudo dnf makecache
  2. Install: sudo dnf install procps-ng

Arch Linux:

  1. Sync package databases: sudo pacman -Syu
  2. Install: sudo pacman -S procps-ng

Alpine Linux (Docker):

  1. Update repositories: apk update && apk upgrade
  2. Install: apk add procps

How to resolve PATH issues for 'ps'

  1. Check your current PATH: echo $PATH
  2. If /bin and /usr/bin are missing, temporarily add them: export PATH=$PATH:/bin:/usr/bin
  3. For permanent changes, add this line to ~/.bashrc or ~/.bash_profile: export PATH=$PATH:/bin:/usr/bin
  4. Apply changes: source ~/.bashrc

Ensure you're using the appropriate file and command for your specific shell configuration.

Alternative methods for using 'ps'

  • Switch to a more complete shell environment like Bash.
  • In Docker with Alpine Linux, install the full 'procps' package.
  • Build from source for customized installation, if development tools are available.

These approaches can help overcome limitations in minimal environments and provide access to a more robust version of 'ps'.

Did you know? The 'ps' command stands for "process status" and provides a snapshot of the currently running processes on a system1.

A developer exploring alternative methods for using the 'ps' command in different environments

Writio: Your automated content creation solution. This article was crafted by Writio.

  1. Linuxize. PS Command in Linux (Process Status). Linuxize. 2019.

Leave a Reply