How to run "nvm" in "oh my zsh"?

Rtx picture Rtx · Oct 30, 2017 · Viewed 54.3k times · Source

In the system there is a nodejs, installed through nvm. The command is not running npm. Console is Oh my zsh

Answer

Ryan Wu picture Ryan Wu · Oct 30, 2017

You can use zsh-nvm or enable it yourself by adding following lines to your ~/.zshrc

 export NVM_DIR=~/.nvm
 [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Extra:

For faster shell initialization, I use lazynvm which only loads node when needed

lazynvm() {
  unset -f nvm node npm
  export NVM_DIR=~/.nvm
  [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
}

nvm() {
  lazynvm 
  nvm $@
}

node() {
  lazynvm
  node $@
}

npm() {
  lazynvm
  npm $@
}

Reference: Lazy load nvm for faster shell start