How to make nvm auto-retrieved on login

I am using nvm for node version control.

I like to do nvm for login, so I don't have to do it manually every time I login.

there is a .bashrc file in my user home directory. I added the following two lines to the end of the file. then restart my mac os. after login, nvm is not the source. I have to manually start them again. I don't understand what happened. please, help.

. ~/nvm/nvm.sh

nvm use 0.8.20

      

+3


source to share


3 answers


You need to put in .bash_profile

this line

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

      

Upload the original file ( source ~/.bash_profile

), or open the shell again, and then in the shell do:



$ nvm alias default <version>

      

This will load node into any new shell you open.

+5


source


.nvmrc

File usage

It turns out that it is enough to create a file .nvmrc

in your home directory. It loads automatically when you open a terminal.

To create a file .nvmrc

with the version we want to run (0.12.2), do the following:

echo '0.12.2' > ~/.nvmrc

      

If this does not work for some reason, dial nvm

from your.bashrc



But only if you are working online.

Add a command to run nvm use 0.12.2

(or whatever version you want to run) if the shell runs interactively to the end .bashrc

.

echo '[[ $- == *i* ]] && nvm use 0.12.2' >> ~/.bashrc

      

Boom, done! :)

+2


source


For Mac, at least open your .profile file and add this line to

[[ -s $HOME/.nvm/nvm.sh ]] && source "$HOME/.nvm/nvm.sh" 
# Load NVM into a shell session *as a function*

      

Done, bingo bango, GG.

0


source







All Articles