Nvm: "node: command not found" every time terminal opens

Created on 10 Nov 2018  Â·  20Comments  Â·  Source: nvm-sh/nvm

Every time I open a new terminal window or start a new process I have to type nvm use --delete-prefix v10.13.0 before node is added to the path.

The README.md says I can use nvm alias default node to set a default node version to be used in any new shell, but this command doesn't do anything. Node is never on the path when a new process starts.

  • Operating system and version:
    Mac OS X High Sierra
  • nvm debug output:
nvm --version: v0.33.11
$TERM_PROGRAM: iTerm.app
$SHELL: /bin/bash
$SHLVL: 1
$HOME: /Users/jason
$NVM_DIR: '$HOME/.nvm'
$PATH: $NVM_DIR/versions/node/v10.13.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
uname -a: 'Darwin 17.7.0 Darwin Kernel Version 17.7.0: Wed Oct 10 23:06:14 PDT 2018; root:xnu-4570.71.13~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.13.6 17G3025
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
wget: not found
git: /usr/local/bin/git, git version 2.10.1
grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed,
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut,
basename: illegal option -- -
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename,
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
rm: /bin/rm,
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir,
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
xargs: /usr/bin/xargs,
nvm current: v10.13.0
which node: $NVM_DIR/versions/node/v10.13.0/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v10.13.0/bin/npm
npm config get prefix: /Users/Jason/.nvm/versions/node/v10.13.0
npm root -g: /Users/Jason/.nvm/versions/node/v10.13.0/lib/node_modules

  • nvm ls output:
->     v10.13.0
default -> v10.13.0
node -> stable (-> v10.13.0) (default)
stable -> 10.13 (-> v10.13.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.4 (-> N/A)
lts/carbon -> v8.12.0 (-> N/A)
lts/dubnium → v10.13.0

Most helpful comment

@maxwellgerber nvm alias default node also works, in lieu of an .nvmrc file.

All 20 comments

When node is not added to the path, what do npm config prefix and which npm print out?

I had this problem with a new laptop the other day.
I was trying to call node before nvm had been initialized - and I don't have node on my default path.
I moved this further up in my .bashrc

 echo loading nvm conf
 export NVM_DIR="$HOME/.nvm"
 [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

and then I added a .nvmrc file to my home directory.

@maxwellgerber nvm alias default node also works, in lieu of an .nvmrc file.

No, nvm alias default node doesn't do anything. I'm not using an .nvmrc file either.
[EDIT: Never mind, I just got it to work:
npm config delete prefix
npm config set prefix $NVM_DIR/node/v10.14.1
nvm alias default node
Deleting the prefix without setting it afterward will make it keep coming back every time you open a window.]

@jtiscione you should never need a prefix set. That implies you have either a prefix line in ~/.npmrc or an env var that’s setting it.

I don't have any ~/.npmrc file. What environment variable is doing it?

If I type npm config delete prefix and then don't set it to something, the "nvm is not compatible with the npm config "prefix" option" error comes right back.

Also, globally installed npm packages don't appear on the path anywhere.

What do you get with env | grep -i prefix?

It doesn't print anything.

Ok - what does npm config get prefix print out, prior to doing anything with nvm?

Well, before doing anything with nvm, npm config get prefix just prints "Command not found".
If I do nvm use --delete-prefix v10.14.1 then npm config get prefix prints "/Users/Jason/.nvm/versions/node/v10.14.1".

I'm having none of these problems on my other laptop... I'll have to compare them side by side.

I think i see the problem. $HOME has “jason” but your other paths have “Jason”. Is there a reason that the capitalization doesn’t match?

Didn't spot that- but this is a Macbook and the path is case insensitive. Commands in there still work regardless of the directory- i.e. /uSeRs/Jason/.nvm/versions/node/v10.14.1/bin/node -v prints "v10.14.1" (if it's there).

Yes, but nvm’s prefix comparison is case sensitive.

Well, on the Mac where it does work, the home folder's case does match- because when I set that machine up a year ago, I renamed the home folder to lower case. (Usually when you set up a mew MacBook the home folder ends up capitalized; you have to create a special System Administrator account from which to rename it.)

That might be the problem - what does whoami print out?

OK; I created another admin user, renamed my home folder from "Jason" to "jason" (since $USER, $PATH, and whoami output all have my name in lower case), logged back in as myself, blew away ~/.nvm, reinstalled nvm from scratch, and now all these weird problems seem to be gone, including the thing with global modules not making it onto the path.

But if this really is just a matter of case sensitivity weirdness for a user's home folder name on a Mac, I wouldn't expect to be the only one running into it.
(I'm not sure why the folder was capitalized. System Preferences on this thing seemed to think the home folder was already /Users/jason, so I had to use mv Jason jason to fix it.)

I agree - i suspect that you have something in your dotfiles that references one capitalization, and you used a different one when first setting up the Mac. The typical case on a Mac is to use the same capitalization from account creation, everywhere, which (if my hunch is right) might be why others aren’t running into it.

I must have set up my work machine a little more carefully than the one under the Christmas tree...

I think we’ve figured out the cause, so I’m going to close this - happy to reopen if there’s more to be done.

I had this problem with a new laptop the other day.
I was trying to call node before nvm had been initialized - and I don't have node on my default path.
I moved this further up in my .bashrc

 echo loading nvm conf
 export NVM_DIR="$HOME/.nvm"
 [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

and then I added a .nvmrc file to my home directory.

however it make my iTerm2 so slow. is it my only problem?

Was this page helpful?
0 / 5 - 0 ratings