Global NPM package installed but command not found
Solution 1
The executable binaries and .cmd files end up in C:\Users\<username>\AppData\Roaming\npm
(minus the node_modules
at the end) so adding that path to the PATH env. variable fixed the issue.
With environment variables, the path can be abbreviated: %appdata\npm
.
Solution 2
If the above method does not work then use this command to explicitly set the path
npm config set prefix c:/Users/<username>/AppData/Roaming/npm
Solution 3
Short answer: Add %APPDATA%\npm
to the PATH
environment variable.
Long answer:
npm saves the .cmd
file which gets executed when you execute a command from a npm package (and everything is working as it should) in the C:\Users\%username%\AppData\Roaming\npm
directory (%username%
is the username of the current user).
Because userprofiles are not necessarily inside of C:\Users
it's better to use a variable like %userprofile%
which points to the userprofile of the current user or %APPDATA%
which points to AppData\Roaming
inside of the userprofile of the current user.
By adding %APPDATA%\npm
to the PATH
env. variable windows automatically searches there for a file with the name you entered as a command if the current directory doesn't contain a file with that name.
For every command there is also a file without a suffix in the npm folder which is a bash script and wont work on Windows (if you don't use bash) but Windows finds the .cmd
file first so you don't have to worry about that.
Solution 4
Here more info about this topic : https://medium.com/@alberto.schiabel/npm-tricks-part-1-get-list-of-globally-installed-packages-39a240347ef0
List of packages which have been install globally
npm list -g --depth 0
Solution 5
Set your PATH
environment variable to C:\Users\YOUR_USERNAME\AppData\Roaming\npm
. This fixed it for me.
bendulum
Updated on February 16, 2022Comments
-
bendulum about 2 years
I have globally installed two npm packages "download" and "enigmavirtualbox" via command line:
npm install -g download
andnpm install -g engimavirtualbox
I'm trying to use them in a batch file to bundle a single .exe file from my node project. For both, the commands
npm list -g <packagename>
yield the respective version output, independent of the present working directory.However, inside my batch script the commands "download" and "enigmavirtualbox" cannot be found.
Running
npm root -g
yieldsC:\Users\<username>\AppData\Roaming\npm\node_modules
and looking inside that folder I can see that folders for both packages are present.What I have tried:
- Changing
npm root
as described here - Uninstall and reinstall packages
- Add env. variable NODE_PATH to point to
C:\Users\<username>\AppData\Roaming\npm\node_modules
- Add
C:\Users\<username>\AppData\Roaming\npm\node_modules
to PATH env. variable
The same setup works on my second computer (both run Win7 64bit). Is something wrong with my node installation, or what am I doing wrong?
- Changing
-
Watchmaker over 7 yearsThat works, although maybe it would be better to use a wildcard:
%USERPROFILE%\AppData\Roaming\npm
. That line has to go before any npm, node or nodejs paths in your PATH env variable, so that npm can find your global packages appropriately. -
deed02392 about 7 yearsI have created my own node package.json and ran
npm install -g
from there (I haven't published it as I need it to stay private). This puts the package data and dependencies in%appdata%\npm\node_modules
but there's no.cmd
file where you said. -
Luk Aron over 4 yearswhat's the path for mac ?
-
theking2 over 4 yearsThe entry is in my path variable gulp can be found bug gulp-sass not. Not working for me.
-
Mick almost 4 yearsHe asked for "command not found" not for listing the installed packages
-
Jürgen 'Kashban' Wahlmann almost 4 yearsFunny enough that variable is set and added correctly, still not found. The Answer of Mr.Noob did it for me (Windows 10).
-
aturc over 3 yearsThis also works if you don't have admin privileges, which is nice...
-
General Grievance about 2 yearsOr if you want to add it to your PowerShell profile:
$env:Path = "$env:appdata\npm;$env:Path"