Set node version with NVM or install if not available.

后端 未结 1 376
梦谈多话
梦谈多话 2021-01-15 20:42

I\'m trying to add to my bash profile something that will set my node version to a specific version, and if the node version is not installed then install it. What I have so

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 20:51

    Have you tried grepping nvm ls?

    . /usr/local/opt/nvm/nvm.sh
    if [[ $(nvm ls | grep v6.9.1) == "" ]]; then
      nvm install v6.9.1
    else
      nvm use v6.9.1
    fi
    

    Is it any faster than using nvm install v6.9.1 for you?

    EDIT: You can also set a default version that will always be loaded by default. You can do it by running nvm alias default 6.9.1.

    You can try changing your script to this:

    if [[ $(node -v) != "v6.9.5" ]]; then
      nvm install v6.9.5
      nvm alias default v6.9.5
    fi
    

    It will take a little long, but just for the first time

    0 讨论(0)
提交回复
热议问题