Nvm: `nvm use #{version} --default`

Created on 19 Dec 2010  路  6Comments  路  Source: nvm-sh/nvm

nvm use #{version} --default should cause future shells for the same user automatically to be using node-#{version}. When using the --default option, the choice of version to use should be persistent between sessions.

This would be similar to how rvm use #{version} --default works for managing Ruby versions.

Most helpful comment

This is implemented via the new alias command.

nvm alias default v0.4.1

or if you're brave

nvm alias default stable

All 6 comments

Neat idea, but it's fairly hard to implement. How would I store the preference?

I'm not entirely sure how this would work. The best bet is to discover what RVM is already doing.

One possibility, though, is to store the value in a file somewhere within in ~/.nvm (for example, ~/.nvm/prefs/default). The shell script would check for this file every time it is run. If the file exists, and if its contents are exactly equal to the name of a version of Node.js that is currently installed via NVM, then the shell script would also mimic an invocation of nvm use #{version}. Since the shell script is only sourced from within ~/.bashrc, it only runs once per shell session.

That sounds good, I'll take a patch for it. I don't think my bash skills are up to the challenge.

Hello @creationix, et al,

I've started hacking on this and would appreciate a review, here's the compare

So far I've just tried implementing the ~/.nvm/prefs/default hook. I had to change how $NVM_DIR is looked up, as I wanted this to execute upon session creation; Not entirely sure this is the best way to do this.

Try it out, just create a symlink like:

ln -s ~/.nvm/v0.4.0/bin/node ~/.nvm/prefs/default

Then just add this modified version of nvm to your PATH:

. nvm.sh

Note: you will likely need to create the ~/.nvm/prefs directory first ;)

Thanks!

This is implemented via the new alias command.

nvm alias default v0.4.1

or if you're brave

nvm alias default stable

Awesome, thanks for the update Tim!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickngqs picture nickngqs  路  3Comments

ssbothwell picture ssbothwell  路  4Comments

dtgriscom picture dtgriscom  路  4Comments

pixelchutes picture pixelchutes  路  3Comments

goalidea picture goalidea  路  3Comments