Sudo Command Not Found

Posted on
  1. Bash Sudo Command Not Found Windows
  2. Sudo Command Not Found Mac Recovery
  3. Sudo Command Not Found Centos

I am trying to deploy django app.When I print apt-get updateI see

Installing a package: sudo apt-get install. Removing a package: sudo apt-get remove. Updating a package: sudo apt-get update. Upgrading a package: sudo apt-get upgrade. For information about the command: apt-get help apt-get: command not found Check your operating system; The APT packages are used in Debian operating systems and its.

When I print sudo apt-get updateI see

I tried to use su instead of sudo.But it is strange. For example I print su apt-get updateAnd nothing happensI just see a new line,

The same if I try to install some packages.What do I do?

If it is useful info - I am using Debian

Tomasz
10.9k7 gold badges35 silver badges73 bronze badges
user2950593user2950593

3 Answers

By default sudo is not installed on Debian, but you can install it. First enable su-mode:
su -

Sudo

Install sudo by running:
apt-get install sudo -y

After that you would need to play around with users and permissions. Give sudo right to your own user.

usermod -aG sudo yourusername

Make sure your sudoers file have sudo group added. Run:
visudo to modify sudoers fileand add following line into it (if it is missing):

You need to relogin or reboot device completely for changes to take effect.

Maksim LuzikMaksim Luzik

Since it's a commercial server you won't have access to root account nor be able to operate with root privileges. This means you won't be able to run sudo nor install packages. What you can try to do is:

  • Check if you have access to a compiler and compile what you want for yourself and in your home space.

  • Check if you can run a virtual machine. This might let you run your private instance of an OS, on which you would install packages.

Bash Sudo Command Not Found Windows

TomaszTomasz

Sudo Command Not Found Mac Recovery

10.9k7 gold badges35 silver badges73 bronze badges

su and sudo are two different, but related commands. It is unusual for sudo not to be installed, but it may simply not be in your Path. Try /usr/bin/sudo command.

If indeed sudo is not available, you need as you surmised to use su, but it does not work in the same way as sudo. The simplest way to use it is to simply run:

This will ask you for the root user's password, at which point you should probably apt install sudo, log out of the root shell, and then proceed as normal.

Mind that unlike sudo, which asks you for your password, su will ask you for root's password.

DopeGhotiDopeGhoti
48.7k5 gold badges63 silver badges98 bronze badges

protected by CommunityMay 2 at 5:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged debianaptsudosu or ask your own question.

I've been updating some of the default profile for bash, and saw from the tutorials I was following that I could reload the new profile with the new environment settings by using:

The only thing is - the new environment variables were only available to my current user - and were ignored when I used sudo. They only became available to sudo when I closed my terminal session and rejoined.

When I try to use:

I get the error:

Is there a simple way to load in the new bash profile settings for sudo without having to close the terminal and restart?

--Initially, I was using some installer scripts which referenced the variables. I found that while they could access the variables when I called the scripts directly (although, this would cause a later problem with creating directories as I needed to be root), calling the install scripts using sudo wouldn't.

I proved this by testing with these simple commands:

Sudo Command Not Found Centos

The first would output the variable's value, but the second wouldn't output anything.

Braiam
53.5k21 gold badges143 silver badges227 bronze badges
HorusKolHorusKol
5272 gold badges8 silver badges30 bronze badges

6 Answers

The problem is that source is a bash build-in command (not a program - like ls or grep). I think one approach is to login as root and then execute the source command.

Marcos Roriz JuniorMarcos Roriz Junior
3,2143 gold badges23 silver badges42 bronze badges

The problem is not that source is a shell builtin command. The fact that it is is what's actually throwing you the command not found error, but it doesn't mean it would work if it were.

The actual problem is how environment variables work. And they work like this:every time a new process is started, if nothing happens, it inherits the environment of its parent. Due to this, using a subshell (e.g. typing bash inside a bash instance) and looking at the output of env should give similar results than its parent.

However, due to how sudo works (as stated in its manpage), sudo tries to strip the environment of the user and create a 'default' environment for the supplanting user, so that the command run is run as if the user who invoked it had been the calling user (which is the expected behaviour), and thus running nautilus as sudo nautilus should open a folder at the /root folder, and not /home/yourusername.

So:

Doing something like sudo source script.sh and then sudo command, even if it worked, it wouldn't be successful at setting any variable to the later sudo command.

In order to pass environment variables, you can either tell sudo to preserve the environment (via the -E switch; and having appropriate permissions in your sudoers file) and/or setting it for the command as sudo VAR1=VALUE1 VAR2=VALUE2 command.

ssicessice

As Marcos says, your main problem here is that source is a shell builtin command that affects only the shell process in which it's run.

The easy solution is to just start a new shell as root, and bash will automatically read /etc/bash.bashrc when it starts. That's as simple as just saying

Community
pooliepoolie
7,4382 gold badges32 silver badges58 bronze badges

Closing and reopening the terminal should not change things. By default, sudo strips the environment. To disable that, add -E to sudo.

psusipsusi
31.7k1 gold badge51 silver badges92 bronze badges
TomDotTomTomDotTom

The error happens because the binary you are trying to call from command line is only part of the current user's PATH variable, but not a part of root user's PATH.

You can verify this by locating the path of the binary you are trying to access. In my case I was trying to call 'bettercap-ng'. So I ran,

I checked whether this location is part of my root user's PATH.

So sudo cannot find the binary that I am trying to call from commandline. Hence returns the error command not found.

You can direct sudo to use the current user's PATH when calling a binary like below.

In fact, one can make an alias out of it:

It's also possible to name the alias itself sudo, replacing the original sudo.

Thomas Ward
46.6k23 gold badges128 silver badges182 bronze badges
Anonymous PlatypusAnonymous Platypus
1,4446 gold badges19 silver badges40 bronze badges

Not the answer you're looking for? Browse other questions tagged command-linebashsudo or ask your own question.