I had NVM installed already, then I discovered oh-my-zsh and installed that. It seems to have an nvm plugin, which I enabled in .zshrc.
Also I put this in my .zprofile
export NVM_DIR="/Users/me/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Now I can use nvm, but whenever I set alias default to a different version, nvm switches back the next time I open the shell.
$ iojs -v
v1.2.0
$ which iojs
/Users/me/.nvm/versions/io.js/v1.2.0/bin/iojs
$ nvm use 1.5.1
Now using io.js v1.5.1
$ nvm alias default iojs v1.5.1
default -> iojs (-> iojs-v1.5.1)
$ which iojs
/Users/me/.nvm/versions/io.js/v1.5.1/bin/iojs
Then after opening a new shell:
$ which iojs
/Users/me/.nvm/versions/io.js/v1.2.0/bin/iojs
Could my old bash install somehow mess things up? I'm on OSX btw but I guess it doesn't make a difference.
--------- edit ------ More output as requested
➜ ~ nvm version
iojs-v1.2.0
➜ ~ ls $NVM_DIR/alias
default
➜ ~ cat $NVM_DIR/alias/default
iojs
➜ ~ nvm alias iojs
iojs -> iojs-v1.5 (-> iojs-v1.5.1) (default)
➜ ~ nvm alias $(cat $NVM_DIR/alias/default)
iojs -> iojs-v1.5 (-> iojs-v1.5.1) (default)
I just found out why it's reverting to 1.2.0 I think. During installation of oh-my-zsh it seems to have taken the active PATH from my Bash shell and copied it to the .zshrc file including the active nvm path at the time:
/Users/me/.nvm/versions/io.js/v1.2.0/bin
But after removing that from PATH, now my zsh can't find any Node binary after launching a new shell. So still the question is I quess, why isn't the NVM setting remembered? I can still set it in the active shell like before, it just doesn't stick.
I'm now thinking there might be something fundamentally wrong with my oh-my-zsh intstallation. I have the git plugin enabled for example in zshrc but the command "gst" is not a valid alias.
plugins=(git, gitflow, nvm, brew, tmux)
➜ ~ gst
zsh: command not found: gst
This zsh plugin allows you to quickly setup nvm once, save it in your dotfiles, then never worry about it again. The plugin will install the latest stable release of nvm if you don't already have it, and then automatically source it for you.
Setting a default NVM version To set the default NVM version, you first have to make sure that version is installed in NVM. We can then run the following command to set this as our default version. You can check which versions you have installed by running the following command.
Just type nvm alias default v10. 16.3 in your terminal and then type nvm use default . This command will make v10. 16.3 available in any shell you open — you just have to restart your terminal to make sure it works.
Add below to the end of .zshrc
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Please note that must be in the end, i don't know why
I have it working now. Reinstalled oh-my-zsh.
I am not sure what has changed. It seems I do need to keep the nvm plugin enabled for it to work.
Without the plugin I tried putting the nvm startup command in .zprofile
export NVM_DIR="/Users/me/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Although the file is loaded on creating a new shell, it didn't seem to enable NVM properly.
Also I noticed that if I make a mistake in the zsh plugin configuration in .zshrc, there is no error and the plugins simply won't work. So this is something to be careful about I guess. For example I used comma's by accident and then the plugins break without warning:
plugins=(git, gitflow, nvm)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With