最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - NVM not recognized after installation - Stack Overflow

programmeradmin0浏览0评论

I have been trying to get nvm to work on my terminal on Mac. I have been following this Tutorial when installing nvm. It gives me this message:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0   143k      0 --:--:-- --:--:-- --:--:--  145k
=> nvm is already installed in /Users/<My profile>/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /Users/<My profile>/.bash_profile
=> bash_completion source string already in /Users/<My profile>/.bash_profile
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

/Users/<My Profile>/.nvm/versions/node/v22.11.0/lib
├── [email protected]
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

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

As you can see it says it is installed and after closing the terminal, reopen the terminal and add this command (see below), and use nvm freely, however, when I close the terminal and reopen it next time it mentions that zsh: command not found: nvm.

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

I have tried this command but doesn't seem like a permanent solution:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

How can I fix this issue?

I have been trying to get nvm to work on my terminal on Mac. I have been following this Tutorial when installing nvm. It gives me this message:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0   143k      0 --:--:-- --:--:-- --:--:--  145k
=> nvm is already installed in /Users/<My profile>/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /Users/<My profile>/.bash_profile
=> bash_completion source string already in /Users/<My profile>/.bash_profile
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

/Users/<My Profile>/.nvm/versions/node/v22.11.0/lib
├── [email protected]
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

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

As you can see it says it is installed and after closing the terminal, reopen the terminal and add this command (see below), and use nvm freely, however, when I close the terminal and reopen it next time it mentions that zsh: command not found: nvm.

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

I have tried this command but doesn't seem like a permanent solution:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

How can I fix this issue?

Share Improve this question edited Feb 3 at 8:06 Mureinik 312k54 gold badges359 silver badges391 bronze badges asked Feb 2 at 6:00 DonDavid12DonDavid12 2091 silver badge11 bronze badges 3
  • 1 It's right there in the documentation... – robertklep Commented Feb 2 at 6:07
  • I have followed those steps but it is still not working. Will try again and come back with results. – DonDavid12 Commented Feb 2 at 6:19
  • 2 The installer is saying that it's placing the commands in ~/.bash_profile, but you're very likely using ZSH (the default shell on macOS). Take particular note of the first item of the link. – robertklep Commented Feb 2 at 6:32
Add a comment  | 

1 Answer 1

Reset to default 1

nvm's installer adds the nescessary setup to .bashrc. However, the error indicates you're using zsh.

The solution is to add this setup to your .zshrc file:

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

Note you'll have to open a new shell for this to take effect. But after the first time, you should be good to go.

发布评论

评论列表(0)

  1. 暂无评论