Command Not Found Using Sudo
1. Introduction
This is an in-depth article related to the Sudo command in Linux and how to avoid command not found error. Sudo is super user do command . It is used as a prefix for superuser commands to be executed. The privileges while executing will be of superusers. In windows, the equivalent is run as administrator. sudo permission is granted by adding the user in sudoers file in /etc/sudoers. This file can be edited using vimudo. Command not found error occurs due to lack of privileges or environmental variables to access the executable are not set.
2. Sudo Command
Sudo command is used in linux and other OS – bash terminals.
2.1 Prerequisites
A bash terminal is required if the operating system is other than linux.
2.2 Download
You can download cygwin at this link. Cygwin is an emulator on windows operating system
2.3 Setup
Ensure that your username is added to /etc/sudoers. You need to have the administrator privileges.
2.4 What is Sudo ?
Sudo is a command in linux to execute like a super user or administrator. The command has various options are shown below.
Sudo command
sudo -V | -h | -l | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] | [ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ] [ -u username|#uid ] commandsudo -V | -h | -l | -L | -v | -k | -K | -s | [ -H ] [-P ] [-S ] [ -b ] | [ -p prompt ] [ -c class|- ] [ -a auth_type ] [-r role ] [-t type ] [ -u username|#uid ] command
2.5 $PATH Variable
$PATH is an environment varialble which has list of paths. These paths are used in the command. echo command is used to print the value of $PATH.
Echo command
echo $PATH
2.6 Fixing the Error for a Single Command
Command not found error can be avoided by exporting the path. This export is for that session in a shell or a terminal window. Below is the export command.
Export command example
export PATH=/usr/java//bin:$PATH
2.7 Fixing the Error Permanently
To fix the command not found error, export command can be added in .profile. The .profile can be sourced to reflect the changes. Every time, user logins into this shell, .profile gets executed. In bash, it is .bash_profile. /etc/profile.d is another option.
Profile update
touch ~/.profile source ~/.profile
3. Download the Source Code
You can download the full source code of this example here: Command Not Found Error When Using Sudo