Igor N. Igor N. - 26 days ago 18
Node.js Question

npm webpack: coomand not found

I'm running this command on linux:


sudo npm install -g webpack


I'm getting the following output:


/home/igor/.npm-global/bin/webpack ->
/home/igor/.npm-global/lib/node_modules/webpack/bin/webpack.js
/home/igor/.npm-global/lib └── webpack@1.13.3


which looks perfectly legit, but when I try to use:


webpack -h


I get the


webpack: command not found


How can I make webpack running from the command prompt?

Answer

The default directory for globally installed NPM modules is /usr/local, which will install the module binaries inside bin folder. If you echo your $PATH environment variable you'll see that /usr/local/bin is in your path. That means when you run a command like webpack, macOS will try to find the binary in this folder or any other folder on your $PATH.

At some point you probably changed it to ~/.npm-global, which installed webpack binary into your /home/igor/.npm-global/bin/. As this folder is not in you $PATH, macOS did not find it. You can run npm config get prefix to confirm this.

Solution 1 is to add it to your path by changing your ~/.profile file. Just append export PATH=~/.npm-global/bin:$PATH to it and restart your terminal.

Solution 2 is to change back the default folder to /usr/local by running npm config set prefix '/usr/local'. In this case you won't need to change your PATH variable.

Comments