Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm global install does not add packages to PATH on Windows 8.1

When I run npm install -g <package> it installs the packages in my user/AppData/Roaming/npm/npm_modules/ folder. This sub-folder is not in my PATH so if I try to run the package without explicitly calling the entire path the call fails with a '<package>' is not recognized as an internal or external command, operable program or batch file.

What can I do to fix this?

Thanks

like image 321
Zain Rizvi Avatar asked May 25 '14 21:05

Zain Rizvi


People also ask

Where do global npm packages get installed?

Path of Global Packages in the system: Global modules are installed in the standard system in root location in system directory /usr/local/lib/node_modules project directory. Command to print the location on your system where all the global modules are installed.

Does npm install add to path?

Globally installed npm packages location On macOS computers, npm will be installed under /usr/local/bin/npm soft link path. The actual path to the npm package is under /usr/local/lib/node_modules . Any globally installed packages will end up in that path as well.

Where do npm global installs go Windows?

Global installs on Unix systems go to {prefix}/lib/node_modules . Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)

What is global installation in NPM?

In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package. What is installing globally and locally?

Where are npm packages installed?

On Windows computers, global NPM packages should be installed under the roaming/ folder. Like in Unix-based systems, you can use the npm list -g command to find your global node_modules/ folder location: Now you’ve learned how to find where NPM packages are installed globally.

How do I find the path to install a package globally?

These are typical npm paths if you install a package globally: Just press windows button and type %APPDATA% and type enter. Above is the location where you can find \npm\node_modules folder. This is where global modules sit in your system.

How do I change the path of the NPM installation directory?

The directory needs to be on the path, so use setx .. /M to set the system path (under HKEY_LOCAL_MACHINE). This is what requires you to run this in a shell with administrator permissions. Tell npm to use this new path.


1 Answers

I'm using win8.1 and I found that the nodejs installer didn't add the path to global node modules to the system PATH. Just add %AppData%\npm; to the user variable(since %AppData% dir is depending on user) PATH to fix it.

You will need to log out then log back in for the change to your PATH variable to take effect.

SET PATH=%AppData%\npm;%PATH% 
like image 112
luochen1990 Avatar answered Oct 16 '22 16:10

luochen1990