Fix: sudo command not found

If you’re an experienced Linux user, then you’ll probably find a sudo command not found error extremely disconcerting. You’ve more than likely gotten used to putting sudo in front of any command you need privileged administrator access for. This is doubly true if you’re a user of Ubuntu or any of its derivatives since these operating systems hash out the root account by default thus requiring you to use sudo quite often.

The sudo command itself isn’t included in some distributions of Linux by default, which often includes those geared toward Web and router management. It’s also not included with many versions of the BSD operating systems. Fortunately, it’s not hard to login as root and then install the package individually.

Method 1: Fixing sudo command not found errors on GNU/Linux

It’s highly unlikely you’re using a Linux distribution that doesn’t come with sudo, but if you type something like sudo fdisk -l and push enter only to find you get an error such as sudo: command not found or ash: sudo: command not found depending on whether you’re using the bash or Almquist shell, you might be using one that doesn’t have it. In our example, we set up a virtual machine and tried to use sudo rm to remove files only to get an error. Type whereis sudo to see if that tells you whether it’s installed somewhere. If you just get sudo: as a reply from that command, then you probably don’t have it installed.

You’ll need to be logged in as the root user to fix a sudo command not found, which is hard because you don’t have sudo on your system to begin with. Hold down Ctrl, Alt and F1 or F2 to switch to a virtual terminal. Type root, push enter and then type the password for the original root user. You’ll receive a # symbol for a command prompt.

If you have a system based on the apt package manager, then type apt-get install sudo and push enter. Those who have yum RPM systems based perhaps on Fedora or Red Hat Linux can use the yum install sudo package management command. Agree to the prompts and then wait for the installation. It should be very quick, but you’ll need networking access for it to work.

Now from the root prompt type visudo and push enter. You’ll either receive a nano or vi editor screen. All the way at the bottom of the file include a line that has your user’s name followed by ALL=(ALL) ALL, keeping in mind that your user name is more than likely in lower case. Hence:

user ALL=(ALL) ALL

If you’re working with vi, then push Esc and type :wq to exit. Those using GNU nano should hold down Ctrl and O to save the file followed by Ctrl and X to exit. Type exit at the prompt and you can now use sudo like normal. It should only take a few very simple commands to fix this problem, but fortunately with the inclusion of sudo in most modern distributions it doesn’t tend to be an issue anymore. *BSD users tend to have a bigger issue.

Method 2: Fixing sudo command not found errors on FreeBSD and Other Unices

While BSD operating systems generally come with su, they seldom if ever come with the actual sudo command. Make sure that you’re logged out of your user account and are currently at the Unix login screen. Type root as a user name then push enter followed by the root password and push enter again.

You’ll have an octothorpe in your prompt to indicate that you’re running as a privileged user. To add the binary package for sudo, type pkg_add -rv sudo and push enter. Agree to install it if asked and then wait for the installation. Once it’s installed, type visudo and push enter. Let’s say you want to allow a user named billy to execute any command. Add the following line at the end of the file:

billy ALL=(ALL) ALL

Of course, you’ll want to replace billy with your actual user name. If visudo actually used vi, then push Esc and type :wq to exit the editor. You can log out and then use sudo like normal.


Kevin Arrows

Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.