[macos] Command not found after npm install in zsh

I'm having some problems installing vows via npm in zsh. Here's what I get. I tried installing it with and without the -g option. Do you have any idea what's wrong here?

[?  ~/Desktop/sauce-node-demo:master] npm install -g vows
npm http GET https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/eyes
npm http GET https://registry.npmjs.org/diff
npm http 304 https://registry.npmjs.org/eyes
npm http 304 https://registry.npmjs.org/diff
/usr/local/share/npm/bin/vows -> /usr/local/share/npm/lib/node_modules/vows/bin/vows
[email protected] /usr/local/share/npm/lib/node_modules/vows
+-- [email protected]
+-- [email protected]
[?  ~/Desktop/sauce-node-demo:master] vows
zsh: command not found: vows

Thanks

This question is related to macos zsh npm vows

The answer is


If you installed Node.js using Homebrew, npm binaries can be found in /usr/local/share/npm/bin. You should make sure this directory is in your PATH environment variable. So, in your ~/.zshrc file add export PATH=/usr/local/share/npm/bin:$PATH.


FOR MAC: I tried some of the above but to no avail, could not get anything to work.

I did have BREW INSTALLED, so although this not be the best approach, with zsh, I did:

  1. sudo chown -R $(whoami) /usr/local/share/man/man8 (for brew access)
  2. brew update && brew install npm (I had had node installed)
  3. npm -v (to confirm install)
  4. nano ~/.zshrc (to empty file changes and save)

This worked for me. Hope this helps someone. #1 bothers me, but I will live with for now.


I've solved this by brew upgrade node


Mac users only
assuming you installed nvm prior, and npm correctly
(step-by-step guide below on how to install it:
install nvm for Mac users ).

you need to:

Find the '.zshrc' file:

  • Open Terminal.
  • Type open ~ to access your home directory.
  • Press Cmd + Shift + . to show the hidden files in Finder.
  • Locate the .zshrc.

Edit the '.zshrc' file:

  • add: source /Users/_user_Name_/.bash_profile to the top of the file (where _user_Name_ stands for your user.

  • Save the file, and close the Terminal window.


I think the problem is more about the ZSH completion.

You need to add this line in your .zshrc:

zstyle ':completion:*' rehash true

If you have Oh-my-zsh, a PR has been made, you can integrate it until it is pulled: https://github.com/robbyrussell/oh-my-zsh/issues/3440


for macOS users: consider using .profile instead of .bash_profile. You may still need to manually add it to ~/.zshrc:

source $HOME/.profile

Note that there is no such file by default! Quoting slhck https://superuser.com/a/473103:

Anyway, you can simply create the file if it doesn't exist and open it in a text editor.

touch ~/.profile
open -e !$

The added value is that it feels good man to use a single file to set up the environment, regardless of the shell used. Loading a bash config file in zsh felt awkward.

Quoting an accepted answer by Cos https://stackoverflow.com/a/415444/2445063

.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists

Following Filip Ekberg's research / opinion https://stackoverflow.com/a/415410/2445063

.profile is the equivalent of .bash_profile for the root. I think the name is changed to let other shells (csh, sh, tcsh) use it as well. (you don't need one as a user)

getting back to slhck, a note of attention regarding bash:

(…) once you create a file called ~/.bash_profile, your ~/.profile will not be read anymore.


If you have added using nvm please add the following to your .zshrc file and restart the terminal since the binaries of the file are not being detected by zsh shell we specify the path

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

For me the accepted answer for adding export PATH=/usr/local/share/npm/bin:$PATH to .zshrc didn't work. I tried adding the NVM_DIR as well which solved my issue.

  1. Try vi .bashrc
  2. You will find a line like the following. Copy it.

    export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

  3. Paste the copied content to .zshrc file

  4. Restart the terminal

I hope this solves your issue.


Another thing to try and the answer for me was to uncomment the first export in ~/.zshrc

# If you come from bash you might have to change your $PATH. export PATH=$HOME/bin:/usr/local/bin:$PATH


In my humble opinion, first, you have to make sure you have any kind of Node version installed. For that type:

nvm ls

And if you don't get any versions it means I was right :) Then you have to type:

nvm install <node_version**>

** the actual version you can find in Node website

Then you will have Node and you will be able to use npm commands


In my case, i installed node with NVM and after installing z Shell, node and nvm command didn't worked. So what worked for me was installing nvm again with this command :

wget https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
sudo zsh install.sh

Above commands installed nvm again, since node was already installed, it added the node path automatically in .zshrc file and everything worked.


In my case, Reinstalling node solve the issue. Anyone can install the node via below website.

https://nodejs.org/en/download/


On Ubuntu, after installing ZSH, and prevously on the bash terminal installed Node or other packages,

First open:

nano .zshrc

And uncomment the second line:

export PATH=$HOME/bin:/usr/local/bin:$PATH

This works for me, and without writting any line, and I think this option is available on Mac too.


For anyone who is still having problem. Don't forget to logout and login again.


For Mac users:

Alongside the following: nvm, iterm2, zsh

I found using the .bashrc rather than .profile or .bash_profile caused far less issues.

Simply by adding the latter to my .zshrc file:

source $HOME/.bashrc

add source /home/YOUUSERNAME/.bash_profile at the beginning of ~/.zshrc

And all missing commands will be detected.

For Mac users : add source /Users/YOUUSERNAME/.bash_profile


Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to zsh

Conda command not found Zsh: Conda/Pip installs command not found commands not found on zsh How do I update zsh to the latest version? npm global path prefix How to permanently set $PATH on Linux/Unix? zsh compinit: insecure directories Command not found after npm install in zsh Adding a new entry to the PATH variable in ZSH Where to place $PATH variable assertions in zsh?

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?

Examples related to vows

Command not found after npm install in zsh