Skip to content

"nvm use" not persisting #658

Closed
Closed
@YourDeveloperFriend

Description

@YourDeveloperFriend

Sorry, I'm sure this is a duplicate, but I can't find anything in the miriad of issues. I'm running on Ubuntu 14.04, nvm version 0.23.3, and I just recently installed nvm. I used to be on n but I switched here in order to try out iojs, so it's possible that some residual n is conflicting with nvm. I removed all the node versions with n except 0.12.0, uninstalled n, installed nvm, and I properly sourced nvm as mentioned in issue #394. Then I ran into the following issue:

$ nvm current
v0.12.0
$ nvm install 0.10
######################################################################## 100.0%
Now using node v0.10.36
$ nvm current # NOTE: didn't change
v0.12.0
$ node -v
v0.12.0
$ nvm use 0.10
Now using node v0.10.36
$ nvm current
v0.12.0
$ node -v
v0.12.0
$ nvm install iojs
######################################################################## 100.0%
WARNING: checksums are currently disabled for io.js
Now using io.js v1.2.0
$ nvm current
iojs-v1.2.0
$ node -v # NOTE: didn't change AND different from nvm current
v0.12.0

This all works just fine when run in sudo su, but when I exit that shell, it doesn't permeate.

More possible clues:

$ nvm run 0.10 -v
Running node v0.10.36
v0.12.0
$ nvm exec 0.10 node -v
Running node v0.10.36
v0.10.36
$ nvm run iojs -v
Running io.js v1.2.0
v1.2.0

Not sure how to proceed.

Activity

ljharb

ljharb commented on Feb 12, 2015

@ljharb
Member

nvm use isn't meant to persist - it's only for the lifetime of the shell.

You can either do nvm alias default node if you want that to be the default when opening new shells, or, you can make a .nvmrc file that will take precedence anywhere in the current directory, upwards to /.

YourDeveloperFriend

YourDeveloperFriend commented on Feb 12, 2015

@YourDeveloperFriend
Author

I don't understand. It's not persisting at all, let alone for the lifetime of the shell. Please read the issue again:

This is all one shell:

$ nvm current
v0.12.0
$ nvm install 0.10
######################################################################## 100.0%
Now using node v0.10.36
$ nvm current # NOTE: didn't change
v0.12.0
$ node -v
v0.12.0
$ nvm use 0.10
Now using node v0.10.36
$ nvm current
v0.12.0
$ node -v
v0.12.0
$ nvm install iojs
######################################################################## 100.0%
WARNING: checksums are currently disabled for io.js
Now using io.js v1.2.0
$ nvm current
iojs-v1.2.0
$ node -v # NOTE: didn't change AND different from nvm current
v0.12.0

You may have been confused by this comment:

This all works just fine when run in sudo su, but when I exit that shell, it doesn't permeate.

In other words, it works as intended within sudo, but not in my regular shell.

ljharb

ljharb commented on Feb 13, 2015

@ljharb
Member

Ah, sorry, responding too quickly :-)

What does which node, echo $PATH, which iojs, and npm root -g report at all those steps?

reopened this on Feb 13, 2015
ljharb

ljharb commented on Feb 13, 2015

@ljharb
Member

Also, how did you install nvm? (Note that homebrew is not supported or recommended)
Under what user did you install nvm? (nvm must be installed once for each user account you want to use with it; it's not meant for being shared across accounts)

YourDeveloperFriend

YourDeveloperFriend commented on Feb 13, 2015

@YourDeveloperFriend
Author
$ which node
/home/yourdeveloperfriend/.nvm/versions/node/v0.12.0/bin/node
$ echo $PATH
/home/yourdeveloperfriend/.nvm/versions/node/v0.12.0/bin:/home/yourdeveloperfriend/.rbenv/plugins/ruby-build/bin:/home/yourdeveloperfriend/.rbenv/shims:/home/yourdeveloperfriend/.rbenv/bin:/usr/local/heroku/bin:/home/yourdeveloperfriend/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/yourdeveloperfriend/.rvm/bin:~/www/phantomjs/bin:/home/yourdeveloperfriend/.rvm/bin
$ which iojs # no response.
$ npm root -g
/home/yourdeveloperfriend/.nvm/versions/node/v0.12.0/lib/node_modules

I installed nvm via my one user: yourdeveloperfriend. I installed with the install script: curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash - I'm on Ubuntu 14.04. I don't have any other user accounts.

YourDeveloperFriend

YourDeveloperFriend commented on Feb 13, 2015

@YourDeveloperFriend
Author

And don't worry about closing the issue too quickly, I understand you guys probably have a lot of garbage to sort through. Thanks for your help.

ljharb

ljharb commented on Feb 13, 2015

@ljharb
Member

@YourDeveloperFriend When you're in the above situation (where 0.10 and 0.12 are installed, 0.12 is active, and nvm use 0.10 doesn't seem to have any effect), what happens if you do nvm deactivate and then check which node ; node -v?

YourDeveloperFriend

YourDeveloperFriend commented on Feb 13, 2015

@YourDeveloperFriend
Author
$ nvm deactivate
/home/yourdeveloperfriend/.nvm/*/bin removed from $PATH
/home/yourdeveloperfriend/.nvm/*/share/man removed from $MANPATH
$ which node
/usr/local/bin/node
$ node -v
0.12.0
ljharb

ljharb commented on Feb 13, 2015

@ljharb
Member

This is very confusing :-) so, when you start with nvm deactivate, your PATH should be such that nvm current reports "system" (ie, /usr/local/bin/node). From there, nvm use iojs for example should activate the latest io.js version, and your PATH should be such that nvm current and node -v report that io.js version, and so on. From there, nvm use 0.10 should remove the io.js path from your PATH, and then add the 0.10 version to it, and then nvm current and node -v should report the 0.10 version.

The only thing I can thing of is that somewhere in that chain, the PATH changes aren't happening - either the removal, or the addition.

What's the output of alias? Just want to make certain that you don't have any builtins aliased - even though we use command internally for most of them to bypass aliases.

YourDeveloperFriend

YourDeveloperFriend commented on Feb 13, 2015

@YourDeveloperFriend
Author

That was it! I had an alias in my .bashrc setting node='nodejs'. I think I remember needing to put that in there when I first installed nodejs... But why? I guess this has nothing to do with nvm. Thanks!

ljharb

ljharb commented on Feb 13, 2015

@ljharb
Member

ah HA! Yay, thanks for working through it with me!

If you originally installed node via apt, the default Ubuntu package is called "nodejs", so I suspect that's the origin.

YourDeveloperFriend

YourDeveloperFriend commented on Feb 13, 2015

@YourDeveloperFriend
Author

So should I uninstall node via apt? I feel uncomfortable about there being two versions of node on my system, that may be confusing in the future...

55 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ljharb@rocco@jordancardwell@anjum121@fergiemcdowall

        Issue actions

          "nvm use" not persisting · Issue #658 · nvm-sh/nvm