You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

已安装nvm与Node/npm但终端提示‘command not found: nvm/npm’的问题求助

Fixing "command not found: nvm/npm" After Installation

Hey there, let's work through this nvm issue together—this is a super common snag, so we'll get it sorted quickly!

First, Let's Check Shell Configuration

The most likely culprit is that your shell isn't loading the nvm initialization script on startup. Here's what to do:

  1. Identify your current shell
    Run this command to see which shell you're using:

    echo $SHELL
    

    Common outputs are /bin/bash (Bash) or /bin/zsh (Zsh).

  2. Verify nvm's initialization code exists in your shell config file
    nvm should have added this code automatically during installation, but sometimes it misses. Open the config file matching your shell:

    • For Bash: open ~/.bash_profile or open ~/.bashrc
    • For Zsh: open ~/.zshrc
    • For Fish: open ~/.config/fish/config.fish

    Look for these lines (for Bash/Zsh):

    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
    

    If you don't see them, paste the code into the file and save it.

  3. Reload your shell config
    Instead of closing and reopening your terminal, run this command (replace .zshrc with your config file):

    source ~/.zshrc
    

Check for Homebrew Conflicts

Since you have Homebrew installed, there might be a conflict if you previously installed Node via Homebrew. Here's how to confirm:

  • Run which node—if the output is /usr/local/bin/node (Homebrew's default path), that means your system is prioritizing Homebrew's Node over nvm's.
  • To fix this, you can either:
    • Uninstall Homebrew's Node temporarily: brew uninstall node
    • Ensure nvm's path is at the top of your PATH variable (the initialization code we added earlier should handle this, but reloading the config ensures it takes effect).

Test It Out

After completing the steps above, run:

nvm --version
npm --version

You should now see the version numbers instead of the "command not found" error. Also, which node should point to a path inside ~/.nvm/versions/node/.

内容的提问来源于stack exchange,提问作者Atharva

火山引擎 最新活动