6

I am using nvm to manage the node version.

I like to make nvm sourced upon login, so I dont have to do it manually everytime I login.

in my user home directory, there's a .bashrc file. I appended following two lines to the end of the file. then restart my mac os. after I login, nvm is not sourced. I have to manually run them again. coudln't figure out whats wrong. please help.

. ~/nvm/nvm.sh

nvm use 0.8.20
qinking126
  • 11,385
  • 25
  • 74
  • 124

4 Answers4

7

You need to put into your .bash_profile this line

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

Source the file (source ~/.bash_profile) or reopen the shell and then in the shell execute:

$ nvm alias default <version>

That would load node in any new shell you open.

Wtower
  • 18,848
  • 11
  • 103
  • 80
Maldo
  • 106
  • 2
  • 8
4

Using .nvmrc file

It turns out that creating a .nvmrc file in your home directory is enough. It is loaded automatically when you open the terminal.

To create the .nvmrc file with the version we want to run (0.12.2) do this:

echo '0.12.2' > ~/.nvmrc

If that for some reason doesn't work, force load the nvm from your .bashrc

But only if you're running in interactive mode.

Add the command to run nvm use 0.12.2 (or any other version you'd like to run) if the shell is launched in interactive mode to the end of .bashrc.

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

Boom, done! :)

nana
  • 4,426
  • 1
  • 34
  • 48
1

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

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

Done, bingo bango, GG.

ahnbizcad
  • 10,491
  • 9
  • 59
  • 85
0

Please use the official website carefully as I used curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | zsh from https://github.com/nvm-sh/nvm and it automatically does my work from installing to load automatically setup.

Himanshu Joshi
  • 100
  • 1
  • 5