I'm running this command on linux:
sudo npm install -g webpack
/home/igor/.npm-global/lib └── firstname.lastname@example.org
webpack: command not found
The default directory for globally installed NPM modules is
/usr/local, which will install the module binaries inside
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.