The sudo: command not found error occurs because the sudo package is not installed by default on Debian if you provided a root password during the initial operating system installation. [1, 2]

To fix this issue, you must log in as the root user, install the package, and add your user account to the sudo administrative group. [1, 2]

Step 1: Switch to the Root User [1]

You need administrative privileges to install new software. Use the standard switch user command: [1, 2, 3]

bash

su -


Gunakan kode dengan hati-hati.

Note: Make sure to include the hyphen (-) so that your terminal loads the correct root path environment variables. Enter your system's root password when prompted. [1, 2, 3]

Step 2: Install the Sudo Package [1]

Update your local package database indices and install the sudo utility from the official Debian repositories: [1]

bash

apt update && apt install sudo -y


Gunakan kode dengan hati-hati.

Step 3: Add Your User to the Sudo Group [1]

Grant your regular user account permission to use the sudo command. Replace your_username with your actual Debian login name: [1, 2]

bash

usermod -aG sudo your_username


Gunakan kode dengan hati-hati.

(Alternatively, you can achieve the same result by running adduser your_username sudo). [1, 2]

Step 4: Exit and Log Back In [1]

Close the root session to return to your normal user state: [1, 2, 3]

bash

exit


Gunakan kode dengan hati-hati.

For the group changes to take effect on your user account, you must completely log out of your system and log back in, or run the following command to apply the group updates inside your current shell: [1, 2, 3, 4]

bash

su - your_username


Gunakan kode dengan hati-hati.

Step 5: Test the Command

Verify that everything is working properly by running a simple test command: [1, 2]

bash

sudo whoami


Gunakan kode dengan hati-hati.

If configured correctly, the terminal will ask for your user password (not the root password) and output root. [1, 2]