How To Fix Sudo Command Not Found In Debian After A New Install

After a new install of Debian, you may find that sudo won’t be available for updating and installing packages from the command line.

sudo command not found after a new Debian install

Besides that, in Debian, the user by default won’t have any sudo privileges either by to make any changes.

Here is how to fix it :

First, switch to root using su (using the root password that was set during installation process).

su root

Having root access, edit the apt sources list. Any text editor like nano or vi can be used for this.

nano /etc/apt/sources.list

editing Debian repository sources list

This is to download and update packages from the online repository rather than look for them from CD ROM / installation media.

On the lines that start with deb cdrom, add a # to comment out the CD ROM apt source. Save the changes and exit. (You can also configure allowing installation of non free packages from here.)

Now, run apt update and then install sudo utility using :

apt update

apt install sudo

installing sudo tool in Debian

What is left now is to add the existing user to sudoers group. Without that, regular user won’t be able to use sudo and error messages like the one below will be seen. Also, you’d need to switch to root everytime to run such commands.

running an update without sudo privilege in Debian

To do this, use visudo command while being root from the command line.


adding a user to sudoers in Debian using visudo

Under User privilege specification section, add the user name with same privileges as root. Save the file and exit.

Now, exit root mode and as regular user, try running  commands with sudo like updating packages or installing new ones.

installing packages as a regular user using sudo in Debian

The updates and installation of new packages in Debian will work as expected.

All done.

By the way, if you want to use a Debian based distros which work right out of the box without making any permission or system changes, here are a few of them.

  1. panikcodes says:

    Great it worked for me.

  2. Dave says:

    Why do you make things so complicated?

    Simply by doing this will do the job (courtesy of the link below):

    apt-get install sudo

  3. Dave says:

    I don’t understand your instructions, especially “On the lines that start with deb cdrom, add a # to comment out the CD ROM apt source. Save the changes and exit.”.