Urgent.News

What's breaking now, across thousands of outlets.

Tech

Fixing “sudo: command not found” on Linux

Seeing sudo: command not found doesn’t necessarily mean you need to install anything. You might already be root, your shell might not be able to find the sudo program, or you may be working in a minimal container that doesn’t include it. Start by checking what account you’re using and how your shell resolves the command: whoami id -u ls -l /usr/bin/sudo echo " $PATH " type sudo If id -u prints 0…

Seeing "sudo: command not found" errors doesn't always mean you need to install the sudo program. There may be other reasons for the issue. Begin by determining your account identity and how your shell locates the sudo command. Issue commands such as whoami, id -u, ls -l /usr/bin/sudo, and echo $PATH followed by type sudo. If id -u outputs 0, you are operating as the root user.

If /usr/bin/sudo exists but type sudo cannot locate it, examine the PATH variable. If the binary file is missing, root access is required to install it. The source outlines several potential problems, including the shell not finding sudo, the user not being in the sudoers file, and the sudo command itself being absent. It advises not to reinstall sudo if you are already root, as root privileges already include elevated access.

To install sudo, switch to a root shell or use another authorized method to gain root access, then utilize the appropriate package manager for your distribution. For Debian-based systems, use su - to become root and then run apt update and apt install -y sudo. Then add your user account to the sudo group using usermod -aG sudo yourusername.

For other distributions, refer to similar commands such as pacman -S sudo on Arch, dnf install -y sudo on Fedora, or apk add sudo on Alpine. Sometimes, authorization issues arise even when sudo is installed. In this case, investigate the distribution's specific configuration methods. After confirming the installation, check whether the PATH environment variable or shell startup files are causing any issues.

Commands like echo $PATH and type sudo can help identify problems with the PATH variable or unintended aliases. If necessary, modify the relevant startup files or aliases and restart your shell session. For minimal containers or new server accounts, remember that omitting sudo is often intentional due to resource constraints. When setting up a new user with administrative privileges, treat creating the user, installing sudo, and granting sudo permissions as separate tasks.

To simplify troubleshooting, follow a step-by-step order: check your current user identity, look for the existence of /usr/bin/sudo, validate the PATH variable, and finally, verify sudoers authorization if needed.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Find the Right IP Address on Linux (Without Guessing)

If hostname -I prints three addresses and you’re not sure which one to use, the problem isn’t finding an IP—it’s identifying what each address is for.

  • Use hostname -I for quick IP overview
  • Employ ip -br addr show for interface-specific details
  • Check public IP with curl ifconfig.me

Linux mkdir: Create Directories, Build Paths, and Fix Common Errors

Creating a directory from the Linux command line is simple; choosing the right path and understanding why a command fails are the parts that tend to trip people up.

  • Use mkdir command to create directories on Linux.
  • Specify relative or absolute paths with mkdir.
  • Use -p option to create directory tree with missing parents.

Copying Directories in Linux: Choose Between cp -r, cp -a, and rsync

Copying a directory in Linux is easy; copying it to the right shape is where mistakes happen. The destination may end up with an unexpected nested folder, hidden files may be skipped by a wildcard, or…

  • Use cp -r for basic directory copy, preserving directory tree structure
  • Include dot for hidden files in source path when copying with cp -r
  • Use cp -a for metadata preservation, symbolic link handling in cp

More from Friday 2 October →