Search code examples
zshoh-my-zshnvm

NVM doesn't stick to alias default with ZSH (oh-my-zsh)


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

Solution

  • 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