how to set the default node version?? After restarting server

$ nvm ls:

     .nvm
 v0.11.12
 v0.11.13

I have to keep hitting nvm use v.0.11.13 in every session:

     .nvm
 v0.11.12

-> v0.11.13 I've tried both the brew install, as well as the official installation script.

2 answers

  • answered 2018-10-17 08:17 Atishay Jain

    use this in the terminal.

    $ nvm alias default v0.11.13
    

    for more help go to https://github.com/creationix/nvm or write nvm help in terminal.

  • answered 2018-10-17 09:58 SinDeus

    Try putting a .nvmrc file at the root of your project. It shall contain:

    v0.11.13
    

    Then, you could add this little snippet at the end of your ~/.bashrc (or whatever bash you're using):

    # Use node version (nvm use)
    autoload -U add-zsh-hook
    load-nvmrc() {
      if [[ -f .nvmrc && -r .nvmrc ]]; then
        nvm use
      elif [[ $(nvm version) != $(nvm version default)  ]]; then
        echo "Reverting to nvm default version"
        nvm use default
      fi
    }
    add-zsh-hook chpwd load-nvmrc
    load-nvmrc
    

    This should properly set the node version as soon as you enter a directory containing a proper .nvmrc file.