After running yarn global add @nestjs/cli
command, if you are getting the error "nest command not found", there could be a few reasons for this issue. Here are some possible solutions:
- Method 1: Update the PATH Environment Variable (Recommended)
For Both Windows and Linux:
- Open a terminal or command prompt.
- Check if the global bin directory is in your system's PATH:
- If the global bin directory (where globally installed packages' executables are located) is not included in the PATH, you need to add it.
The Linux command appends the global bin directory to the PATH environment variable, while the Windows command does the same for Windows.
- Verify that the PATH has been updated by running the appropriate command again:
You should see the global bin directory included in the output.
- Method 2: Update Shell Configuration (For Non-Bash Shells)
For Both Windows and Linux:
If you use a shell other than bash (e.g., zsh), you might need to add the global bin directory to your shell's configuration file. Here's how to do it:
- Linux (zsh):
- Open your zsh configuration file in a text editor. Typically, it's
~/.zshrc
.
- Add the following line to the file:
bash export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
- Save the file and restart your zsh shell or run
source ~/.zshrc
to apply the changes.
- Windows (PowerShell):
- Open your PowerShell profile in a text editor. You can check its location using
$PROFILE
in PowerShell.
- Add the following line to the file:
- Save the file and restart your PowerShell session.
- Method 3: Reinstall the Nest CLI Globally
For Both Windows and Linux:*
If the above methods do not resolve the issue, you can try uninstalling and reinstalling the @nestjs/cli
package globally. Run the following commands:
These commands will remove the package and then install it again globally.
- Method 4: Install the Nest CLI Locally (Project-specific)
For Both Windows and Linux:*
If none of the above methods work, you can opt to install the @nestjs/cli
package locally within your project. Here's how:
- Navigate to your project directory in the terminal or command prompt.
- Run the following command to install
@nestjs/cli
as a project dependency:
This will install the package in your project's node_modules
directory, allowing you to use it within that specific project.
By following these instructions that cover both Windows and Linux, you should be able to efficiently resolve the "nest command not found" error when using yarn global add @nestjs/cli
.