zsh: 命令未找到: npm

6

我刚刚使用以下命令安装了Node和Yarn:

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

然而,如果我在终端中输入npm,它会显示“zsh:command not found: npm”。

在我的~/.zshrc文件中,我有:

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

我尝试按照这个指南卸载并重新安装 Node 和 Yarn:如何彻底卸载 Node.js 并从头开始重新安装(Mac OS X)

但我仍然遇到相同的错误。


你安装了 node 或者 yarn 吗?你是用同一个用户运行它们还是不同的用户? - Vishrant
同一个用户。我通过完全卸载 Node 并从官网下载(而不是通过终端安装)的方式解决了这个问题。现在,当我运行“yarn start”时,我会收到一个错误消息。 - Magofoco
请查看 - https://stackoverflow.com/a/75472094/5348972 - Abhishek Sinha
4个回答

7
在我的~/.zshrc文件的开头添加source ~/.bash_profile后,它对我起作用了,同时我还需要删除某些内容。
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"

~/.bash_profile中。这是我从iTerm2意外安装的shell集成。


5
通过完全卸载Node并通过官网安装(而不是通过终端)解决了这个问题。

2

通过运行brew uninstall node并从其官网下载最新版本的Node.js安装程序解决了问题。


1

通过使用nvm选择节点版本解决。

nvm ls

那么

nvm use _version_code

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接