sudo command not found - MacOS

Page content

How to Install sudo Command on MacOS

If you are using a Mac and trying to run a command that requires elevated privileges, you may encounter the “sudo command not found” error. This error occurs because the sudo command is not readily available on MacOS by default.

Installing sudo Command on MacOS

To install the sudo command on MacOS, you can follow these steps:

  1. Open a terminal window on your Mac.
  2. Check if sudo is already installed by running the following command:
    which sudo
    
  3. If sudo is not installed, you can install it using Homebrew. If you don’t have Homebrew installed, you can do so by running the following command in the terminal:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  4. Once Homebrew is installed, you can install sudo by running the following command:
    brew install sudo
    
  5. After the installation is complete, you should be able to use the sudo command to run commands with elevated privileges.

Why sudo is not included by default on MacOS

Unlike some Linux distributions, MacOS does not come with the sudo command pre-installed. This is due to the different design philosophies between MacOS and Linux.

Conclusion

By following the steps outlined above, you can easily install the sudo command on your MacOS system and avoid the “sudo command not found” error when trying to run commands that require elevated privileges.