Home » Linux » Command Not Found Using Sudo

About Bhagvan Kommadi

Bhagvan Kommadi is the Founder of Architect Corner & has around 20 years’ experience in the industry, ranging from large scale enterprise development to helping incubate software product start-ups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is member of IFX forum,Oracle JCP and participant in Java Community Process. He founded Quantica Computacao, the first quantum computing startup in India. Markets and Markets have positioned Quantica Computacao in ‘Emerging Companies’ section of Quantum Computing quadrants. Bhagvan has engineered and developed simulators and tools in the area of quantum technology using IBM Q, Microsoft Q# and Google QScript. He has reviewed the Manning book titled : "Machine Learning with TensorFlow”. He is also the author of Packt Publishing book - "Hands-On Data Structures and Algorithms with Go".He is member of IFX forum,Oracle JCP and participant in Java Community Process. He is member of the MIT Technology Review Global Panel.

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

Download
You can download the full source code of this example here: Command Not Found Error When Using Sudo

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments