Last updated: Apr 4, 2024
Reading timeยท4 min
To solve the error "'yarn' is not recognized as an internal or external
command, operable program or batch file", install the yarn
package globally by
running npm install -g yarn
, restart your terminal and make sure your PATH
environment variable is set up correctly.
Open your terminal and install yarn globally by running the following command.
# ๐๏ธ install yarn CLI globally npm install -g yarn # ๐๏ธ get the version yarn --version
If you see a package version output from the second command, then yarn is installed successfully.
yarn
fails, you have to open CMD as an administrator and rerun the commands.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".
# ๐๏ธ install yarn CLI globally npm install -g yarn # ๐๏ธ get the version yarn --version
If the error is not resolved, try restarting your terminal.
If you got the "yarn command not found" error on macOS or Linux, click on the following article.
npm
to your PATH environment variable on WindowsTo add npm to your PATH environment variable:
npm
directory is most likely located under
%USERPROFILE%\AppData\Roaming\npm
or in other words,
C:\Users\YOUR_USER\AppData\Roaming\npm
.%USERPROFILE%\AppData\Roaming\npm # ๐๏ธ same as below (make sure to replace YOUR_USER) C:\Users\YOUR_USER\AppData\Roaming\npm
If you can't find it, run the npm config get prefix
command.
npm config get prefix
Add the path to npm
and click on "OK" twice to confirm.
Close your Command prompt application and then reopen it.
You might also have to restart your PC, but that's not always necessary.
# ๐๏ธ install yarn CLI globally npm install -g yarn # ๐๏ธ get the version yarn --version
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".
If you get the error yarn.ps1 cannot be loaded because running scripts is disabled on this system, open your PowerShell as an administrator and set its execution policy with the Set-ExecutionPolicy command.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Set-ExecutionPolicy
command.This effectively removes the execution policy of Restricted
, which doesn't
allow us to load configuration files or run scripts. The Restricted
execution
policy is the default for Windows client computers.
If the error persists, try to reinstall Node.js.
The easiest way to install Node and add it to your system's PATH environment variable is to:
Next
on the Welcome screen.Next
.Next
.Next
. Notice that there is an "Add to
PATH" option.Next
.Install
button.Finish
button.Make sure to close any existing command prompts and PowerShell instances for the PATH variable to get updated.
You can start a new CMD shell and use the npm --version
command to make
sure Node is installed.
npm --version node --version
# ๐๏ธ install yarn cli globally npm install -g yarn # ๐๏ธ get package version yarn --version
yarn
fails, you have to open CMD as an administrator and rerun the commands.Alternatively, you can see how you can fix the permissions error on this page in the official npm docs.
If you have difficulties installing and setting up Node.js correctly, try using NVM to manage your Node.js version.
Click on the article that relates to you and follow the instructions.
I have two more articles on solving yarn-related errors:
You can learn more about the related topics by checking out the following tutorials: