New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"nvm use" not persisting #658

Closed
YourDeveloperFriend opened this Issue Feb 12, 2015 · 47 comments

Comments

Projects
None yet
@YourDeveloperFriend

YourDeveloperFriend commented Feb 12, 2015

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.

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Feb 12, 2015

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 /.

@ljharb ljharb closed this Feb 12, 2015

@YourDeveloperFriend

This comment has been minimized.

YourDeveloperFriend commented Feb 12, 2015

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

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

Ah, sorry, responding too quickly :-)

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

@ljharb ljharb reopened this Feb 13, 2015

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

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

This comment has been minimized.

YourDeveloperFriend commented Feb 13, 2015

$ 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

This comment has been minimized.

YourDeveloperFriend commented Feb 13, 2015

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

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

@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

This comment has been minimized.

YourDeveloperFriend commented Feb 13, 2015

$ 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

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

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

This comment has been minimized.

YourDeveloperFriend commented Feb 13, 2015

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

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

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.

@ljharb ljharb closed this Feb 13, 2015

@YourDeveloperFriend

This comment has been minimized.

YourDeveloperFriend commented Feb 13, 2015

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...

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Feb 13, 2015

Yes, absolutely. It won't cause problems, but as we've seen it could definitely cause confusion :-)

@fergiemcdowall

This comment has been minimized.

fergiemcdowall commented Oct 1, 2015

Just a not to say that I had been struggling with this for a long time on ubuntu and removing alias node='nodejs' from .bashrc fixed it.

(In pre-nvm days adding the alias to .bashrc was the recommended way of getting to node to run on ubuntu)

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 24, 2015

I'm experiencing this same issue with the latest nvm (0.29.0) - is the protocol to open a new issue?

I have node installed in my system, ran the nvm install script, set the NVM_DIR variable & sourced the nvm shell script in my shell profile.

# /usr/local/bin/node
which node

# v4.2.4
node -v

# /Users/thelostspore/.nvm
echo $NVM_DIR

nvm install 0.12.9
nvm alias default 0.12.9
nvm use default

# /Users/thelostspore/.nvm/versions/node/v0.12.9/bin/node
which node

nvm is installed and behaving normally except that the new shell sessions always revert to the system version of node. Am I missing something?

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 24, 2015

@thelostspore let's debug here for a moment - can you gist the output of nvm debug, and the contents of your bashrc (or appropriate profile) file?

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 24, 2015

Thanks @ljharb

Output of nvm debug:

$SHELL: /bin/bash
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: system
which node: /usr/local/bin/node
which iojs: 
which npm: /usr/local/bin/npm
npm config get prefix: /usr/local
npm root -g: /usr/local/lib/node_modules

~/.bash_profile sources from my ~/.bashrc. The relevant nvm portion:

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

I think its worth mentioning that I first attempted install via the nvm install script, then a manual install, before finally a homebrew install (uninstalling nvm before each new attempt). Currently nvm is installed via homebrew and everything appears to be working aside from the default node version in new shell sessions.

Also, I placed an .nvmrc with the desired default node version in my home directory. Still no luck.

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 24, 2015

nvm is entirely unsupported when installed via homebrew - can you try brew uninstalling it, and installing it just with the install script, and then I should be able to help you get everything working?

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

Ok, uninstalled nvm via homebrew, ran install script, installed node (0.12.9), and set as default.
nvm debug

$SHELL: /bin/bash
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v0.12.9
which node: $NVM_DIR/versions/node/v0.12.9/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v0.12.9/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v0.12.9
npm root -g: $NVM_DIR/versions/node/v0.12.9/lib/node_modules

The nvm command is available in new shells but the system version of node is the default (nvm current).
Thanks again for looking into this.

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 25, 2015

ok so nvm alias default node works? what does nvm alias print out? when you open a new shell, is the above what nvm debug prints out? Can you confirm what nvm current prints out with the above nvm debug printout?

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

I don't think the alias command is working as expected.

nvm use default

# 0.12.9
nvm current

# default -> node (-> v4.2.4) .. this should be 0.12.9, according to `nvm alias`
nvm alias default node

nvm alias

default -> node (-> v4.2.4)
node -> 0.12 (-> v0.12.9)
system -> 4.2 (-> v4.2.4)
stable -> 4.2 (-> v4.2.4) (default)
iojs -> N/A (default)

Same results with nvm alias default 0.12. In a new shell nvm current yields system.

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 25, 2015

aha! @thelostspore try nvm unalias node. you may have ran nvm alias node 0.12 at some point, and I don't think that's a scenario i'd anticipated. also, what's ls -la $NVM_DIR print out?

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

Ok, removed all aliases (I definitely tried nvm alias node 0.12 ;) ), and then tried setting the default again. nvm current in new shells still yields system.

$NVM_DIR

drwxr-xr-x  20 thelostspore  staff   680B Dec 24 16:23 .
drwxr-xr-x+ 52 thelostspore  staff   1.7K Dec 24 16:20 ..
drwxr-xr-x  13 thelostspore  staff   442B Dec 24 16:20 .git
-rw-r--r--   1 thelostspore  staff    12B Dec 24 16:20 .gitattributes
-rw-r--r--   1 thelostspore  staff   117B Dec 24 16:20 .gitignore
-rw-r--r--   1 thelostspore  staff    14B Dec 24 16:20 .npmignore
-rw-r--r--   1 thelostspore  staff   1.4K Dec 24 16:20 .travis.yml
-rw-r--r--   1 thelostspore  staff   763B Dec 24 16:20 CONTRIBUTING.md
-rw-r--r--   1 thelostspore  staff   1.1K Dec 24 16:20 LICENSE.md
-rw-r--r--   1 thelostspore  staff   5.1K Dec 24 16:20 Makefile
-rw-r--r--   1 thelostspore  staff   8.9K Dec 24 16:20 README.markdown
drwxr-xr-x   3 thelostspore  staff   102B Dec 25 11:08 alias
-rw-r--r--   1 thelostspore  staff   1.8K Dec 24 16:20 bash_completion
drwxr-xr-x   4 thelostspore  staff   136B Dec 25 10:51 bin
-rwxr-xr-x   1 thelostspore  staff   7.5K Dec 24 16:20 install.sh
-rwxr-xr-x   1 thelostspore  staff   304B Dec 24 16:20 nvm-exec
-rwxr-xr-x   1 thelostspore  staff    65K Dec 24 16:20 nvm.sh
-rw-r--r--   1 thelostspore  staff   1.4K Dec 24 16:20 package.json
drwxr-xr-x   9 thelostspore  staff   306B Dec 24 16:20 test
drwxr-xr-x   3 thelostspore  staff   102B Dec 24 16:22 versions
@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 25, 2015

great, and inside $NVM_DIR/alias?

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

Only default exists, contents are 0.12

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 25, 2015

ok - so just to confirm once more: new shell, nvm works fine, but nvm current starts out as system, despite the presence of nvm alias default. There's no other aliases. There isn't any .nvmrc file (and adding one doesn't change the behavior), and nvm use 0.12 works fine. What does nvm use with no arguments print out? Also, what about echo $PATH? it's possible that you're setting your system node's PATH after nvm is loaded.

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

:facepalm:

PATH issue. Was sourcing nvm init script before PATH modifications. Sorry to waste your time.

Would it be helpful if I opened a pull and added a few gotchas to the readme?

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Dec 25, 2015

hooray, glad we figured it out. Sure, documentation PRs are always welcome!

@thelostspore

This comment has been minimized.

Contributor

thelostspore commented Dec 25, 2015

👍 Thanks again @ljharb

@g13013

This comment has been minimized.

g13013 commented Jan 13, 2016

for those who have similar problem, forcing npm prefix config also causes this issue!

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Jan 13, 2016

The "prefix" config is not supported by nvm, so please don't use it.

@cornelius-k

This comment has been minimized.

cornelius-k commented Jul 8, 2016

nvm alias default 6.3.0 resolved my issue, version number being the last argument

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Jul 9, 2016

nvm alias default node works as well.

@rocco

This comment has been minimized.

rocco commented Aug 26, 2016

haven't seen such a positive and constructive issue thread in a while - good job @ljharb

@jordancardwell

This comment has been minimized.

jordancardwell commented Sep 9, 2016

FWIW

I had to delete .nvm/current, an alias to the version mine was stuck on.

pretty sure this was a side effect of having installed via brew.

I uninstalled via brew and installed via the README... that current alias, however, was still hanging around.. deleting that resolved it.

also kudos @ljharb for being helpful AF

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Sep 9, 2016

That current alias is from an older version of nvm - by default now, it's not created at all, unless an env var is set.

@wq1308786830

This comment has been minimized.

wq1308786830 commented Apr 27, 2017

image
seems windows nvm have no 'nvm alias default xxx' command, and I still have this problem, want some help

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Apr 27, 2017

@wq1308786830 windows nvm isn't this project; that's nvm-windows - it's linked from the readme. You're on the wrong repo.

@wq1308786830

This comment has been minimized.

wq1308786830 commented Apr 27, 2017

@ljharb thanks

@omkarsheral1989

This comment has been minimized.

omkarsheral1989 commented Dec 15, 2017

use
nvm alias default
eg
nvm alias default 8.9.3

@JonahMoses

This comment has been minimized.

JonahMoses commented Jan 8, 2018

Having similar problems as some other users above and have tried all suggestions given but I'm still seeing some unexpected behavior. I'm on mac os with zsh, installed properly from the readme and most behaviors work as intended, except when I source my zshrc file.

  1. I start a new terminal and it uses 9.3 as my desired default.
  2. I source my zsh file then it reverts to using system node vs default.

screen shot 2018-01-07 at 11 49 44 pm

I should also add that if afterwards I use nvm use default it correctly changes my select to 9.3

Here is whats in my zshrc that seems relevant:
export PATH="~/.yarn/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Jan 8, 2018

The "prefix" error is the issue; do you have an ~/.npmrc file, or any env vars set with "prefix" in their name?

@JonahMoses

This comment has been minimized.

JonahMoses commented Jan 8, 2018

I do not have a /.npmrc file and do not believe I have any env vars set with "prefix".

Also I'm very impressed with your response time and the previous responses you've given. Thank you!

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Jan 8, 2018

@JonahMoses would you mind filing a new issue for this one? I assume that at the end of that screenshot, nvm use node would error out with that prefix error?

@JonahMoses

This comment has been minimized.

JonahMoses commented Jan 8, 2018

@ljharb nvm use node doesn't provide the prefix error but switches to the default node.

I've filed a new issue here: #1703

@anjum121

This comment has been minimized.

anjum121 commented Jan 29, 2018

For me when I do nvm alias default 6.11.0 it wasn't persistent, each time when I close iTerm (my shell) it was getting set to4.4.4, which isn't what I had set.

This trick work for me, goto /Users/anjum/.nvm/alias folder open default file and changed 4.4 to 6.11

Thanks

@ljharb

This comment has been minimized.

Collaborator

ljharb commented Jan 29, 2018

@anjum121 that suggests that the permissions on that file aren't correct; such that nvm alias default whatever is able to change it.

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