Last updated: Apr 4, 2024
Reading time·4 min
The error "'sudo' is not recognized as an internal or external command,
operable program or batch file" occurs because sudo
is a Unix command that is
not available on Windows.
To solve the error, run the command without the sudo
prefix or run CMD as an
administrator before issuing the command.
sudo
is a Unix-specific command that allows you to elevate your permissions.The command is not available on Windows, but you can try to rerun the command
without the sudo
prefix.
# 👇️ your command without sudo dir
If the command you're trying to run requires you to have administrative privileges, then start CMD as an administrator.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
dir
Alternatively, you can open PowerShell as an administrator.
To run PowerShell as an administrator:
dir
You can also run Git Bash as an administrator if you have git
installed.
To run Git Bash as an administrator:
dir
An alternative approach is to install the Windows Subsystem for Linux.
If you start a Bash shell, you can use the sudo
command.
To install Windows subsystem for Linux (WSL):
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
wsl --install -d Ubuntu
command.wsl --install -d Ubuntu
wsl --list --online
command if you want to list all valid
distributions that can be installed.wsl --list --online # 👇️ the syntax for the installation command wsl --install -d DISTRO_NAME
wsl
command is not recognized, use the older
lxrun
command instead.lxrun /install
Close your CMD and PowerShell sessions and reopen your shell as an administrator.
Now you can simply type bash
in CMD to start a bash
shell.
bash sudo apt update ls
bash
command to enter a bash
session before issuing Unix commands.sudo
prefix if you have to issue a command as an
administrator.sudo apt update && sudo apt upgrade
Alternatively, you can install your Linux distribution of choice using Microsoft Store.
To install a Linux distribution using Microsoft Store:
Click on the https://aka.ms/wslstore link.
In the Microsoft Store window, use the Search bar to look for your Linux distribution of choice. For example, Ubuntu 22.04.1 LTS.
After the process is complete, you can click on the Search bar and type "Ubuntu" to start your integrated Linux environment.
Now you can simply type bash
in CMD to start a bash
shell.
bash sudo apt update ls
bash
command to enter a bash
session before issuing Unix commands.You can use the sudo
prefix if you have to issue a command as an
administrator.
sudo apt update && sudo apt upgrade
You can learn more about the related topics by checking out the following tutorials: