zsh: command not found: npm
Asked Answered
G

8

5

I have just installed Node and Yarn using the following commands:

brew install node
brew install yarn --without-node

node -v       
v11.8.0

-a node  
node is /usr/local/bin/node

yarn -v       
1.13.0
type -a yarn
yarn is /usr/local/bin/yarn

However, if I write in terminal npm is says "zsh: command not found: npm"

In my: ~/.zshrc I have:

ZSH=$HOME/.oh-my-zsh

# You can change the theme with another one:
#   https://github.com/robbyrussell/oh-my-zsh/wiki/themes
ZSH_THEME="robbyrussell"

# Useful plugins for Rails development with Sublime Text
plugins=(gitfast last-working-dir common-aliases sublime zsh-syntax-highlighting history-substring-search)

# Prevent Homebrew from reporting - https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Analytics.md
export HOMEBREW_NO_ANALYTICS=1

# Actually load Oh-My-Zsh
source "${ZSH}/oh-my-zsh.sh"
unalias rm # No interactive rm by default (brought by plugins/common-aliases)

# Load rbenv if installed
export PATH="${HOME}/.rbenv/bin:${PATH}"
type -a rbenv > /dev/null && eval "$(rbenv init -)"

# Rails and Ruby uses the local `bin` folder to store binstubs.
# So instead of running `bin/rails` like the doc says, just run `rails`
# Same for `./node_modules/.bin` and nodejs
export PATH="./bin:./node_modules/.bin:${PATH}:/usr/local/sbin"

# Store your own aliases in the ~/.aliases file and load the here.
[[ -f "$HOME/.aliases" ]] && source "$HOME/.aliases"

# Encoding stuff for the terminal
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

I tried to uninstall and reinstall Node and Yarn using this guide: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

But I still get the same error.

Glean answered 27/1, 2019 at 16:48 Comment(3)
which what user you installed node or yarn? and are you running it with same user or different user?Grays
Same user. I managed to solve is by uninstall node completely and download it from the website (not installing it via terminal). Now, however, I get an error message when I run "yarn start".Glean
Check - https://mcmap.net/q/1921360/-zsh-command-not-found-npm-in-the-command-lineGal
G
5

Solved it by uninstalling Node completely and installing it via the website (not via terminal)

Glean answered 27/1, 2019 at 17:51 Comment(0)
M
8

It worked for me when I added source ~/.bash_profile at the beginning of my ~/.zshrc and I had to also remove

test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"

in ~/.bash_profile. This was the shell integration I accidentally installed from iTerm2.

Munificent answered 6/3, 2019 at 16:39 Comment(0)
G
5

Solved it by uninstalling Node completely and installing it via the website (not via terminal)

Glean answered 27/1, 2019 at 17:51 Comment(0)
K
5

Solved it by running brew uninstall node and downloading the latest node installing .pkg from their website.

Kurtzman answered 30/4, 2021 at 17:6 Comment(0)
M
1

solved by selecting a node version using nvm.

nvm ls

then

nvm use _version_code
Melleta answered 3/5, 2022 at 15:56 Comment(0)
P
0

For macOS M2 there is a different way to setup the path.

This solution worked for me.

  • Open Terminal
  • Type open ~ to access your home directory.
  • Press Cmd + Shift + . to show the hidden files in Finder.
  • Locate the .zprofile
  • Open '.zprofile' file.
  • Add this line at top: export PATH=/usr/local/share/npm/bin:$PATH
  • Save file
Pyrrolidine answered 5/4 at 19:18 Comment(0)
B
0
brew update
brew uninstall node
brew install node
sudo chown -R YourLocalUserName /usr/local/lib/node_modules/
brew postinstall node
Bucci answered 3/5 at 6:36 Comment(0)
C
0

Anyone having this issue, and have tried all of the above and doesn't work, I did the following:

  1. Watch and follow this tutorial to completely remove/uninstall node and npm
  2. Reinstall node. Reference the official Node website

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

nvm install 20

node -v

npm -v

  1. Restart your terminal and code editor
Candlepin answered 14/10 at 11:11 Comment(0)
R
-1

I tried to install using NVM:

  • Uninstall Node
  • Run this command to install Node Version Manager curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  • Close all the terminals and reopen. (it's important)
  • Installed the node, current LTS is 20 nvm install 20

To Verify:

  • npm -v

(If it still fails, close your terminal and try npm -v)

Retrusion answered 12/8 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.