How To Fix Su: Command Not Found
When just starting with Linux systems, you might have encountered a tutorial or manual telling you to use the su
command to switch to a given user.
However, depending on the target system, you might encounter an error when invoking the su
command.
In this tutorial, we will learn what the bash: su: command not found
error means, why it occurs and how to resolve it.
What is the su
command?
The su
command, or substitute user or switch user a command-line utility available in Unix-like operating systems. The su
command allows us to change the current user context to another user during a login session.
In simple terms, the su
command allows us to log in as another use in the current system without actually logging out of the current session. This is especially useful when you need to quickly perform specific tasks as another user and then go back to your regular session.
What causes the su: command not found
Error?
If you run the su
command and get the command not found
error, it means that the shell cannot find the su
binary in the PATH
.
The most cause of this issue is you do not have the su
binary installed on your system. It might also mean that you need to reload your shell session if you have just installed the binary,
Install su - Debian/Ubuntu
To resolve this error, the simplest method is installing the su
binary on your system. If you are on Debian, Ubuntu, or any other Debian-based system that uses apt
as the package manager, you can run the command below to install it:
sudo apt-get -y install util-linux
Or:
sudo apt install util-linux -y
Install su - Arch/Manjaro
On Arch Linux and other Arch-based distribution, use pacman
to install su
as shown:
sudo pacman -S util-linux
Install su - Fedora
If you have Fedora, run the command below to install the su
utility on your system:
sudo dnf install util-linux
Install su - CentOS/REHL
If you have CentOS, REHL, Oracle-Linux or any other similar system, use yum to install su as shown:
sudo yum install util-linux
Install su - Alpine Linux
On Alpine Linux, you can use the app command to install su as shown:
sudo apk add util-linux
Install su - macOS
If you are running macOS, you can install the su utility by using Homebrew, as shown in the command below:
brew install util-linux
Conclusion
In this short post, you learned how you can resolve the su command not found error in any Unix-based system by installing the su binary in your system.