0

I want to update npm, but it seems like I have 2 versions and I'm not sure how to best resolve it so I only have one.

My main issue right now is I have some older yeoman generators in
/Users/me/.npm-packages/lib/node_modules/,
but newer ones have gone into /Users/me/.npm-global/lib/node_modules/

When I run yo, it's only finding the older generators.

I'd like to have all my globally installed packages in one place under one user, and I don't want to need to sudo things that I shouldn't need to.

It seems like I have node in/Users/me/.npm-packages/bin/npm and maybe also /usr/local/bin/npm. I've gone to both directories and updated npm in both, but it still returns 2.11.2 rather than 3.8.6 that it claims to have installed. here is some CLIing I've done to try to fix:

➜  ~ which npm
/Users/me/.npm-packages/bin/npm
➜  ~ sudo which npm
/Users/me/.npm-packages/bin/npm
➜  ~ npm install npm@latest
npm@3.8.6 node_modules/npm
➜  ~ npm -v
2.11.2
➜  ~ npm install -g npm@latest
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/Users/me/.npm-packages/bin/npm" "install" "-g" "npm@latest"
npm ERR! node v5.10.1
npm ERR! npm  v2.11.2
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir

..etc
➜  ~ sudo npm install -g npm@latest
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@3.8.6 /usr/local/lib/node_modules/npm
➜  ~ npm -v
2.11.2

I also tried installing nvm and installing the latest version of npm inside of it as described here

My .zshrc has PATH variable set to:

NPM_PACKAGES=/Users/me/.npm-packages
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"

Want to use current node and also standardize where my packages are, and would be ok blowing everything away so it works properly. Hoping this is easy to diagnose for someone who knows more about this stuff than I.

Community
  • 1
  • 1
Damon
  • 10,493
  • 16
  • 86
  • 144
  • Would you feel more comfortable using your global installation? Do you need to have both versions installed? – pandres95 Apr 19 '16 at 05:28
  • I never really wanted to have 2 global versions installed. Main thing is I want to make sure it's owned by me and not root.. or whatever is necessary so I don't need to `sudo` to do global stuff. – Damon Apr 19 '16 at 13:51
  • I see maybe you're using a globally installed version. However, the global packages register (`NPM_PACKAGES` variable) is located in your user. The thing is to unable it and `sudo npm i -g npm@latest`. Then re-enabling your local `NPM_PACKAGES` variables. – pandres95 Apr 21 '16 at 01:10
  • @pandres95 i am a bit fuzzy on terms. global npm.. does that mean owned by root? i think i want 1 npm only when I -g, and I *think* it makes sense for that to be owned by me. – Damon Apr 21 '16 at 03:25
  • I have 2 directories with things that I have installed globally. it switched at some point, I think when I was fixing needing sudo to install things.. – Damon Apr 21 '16 at 03:26
  • I'm not sure how to disable NPM_PACKAGES – Damon Apr 21 '16 at 03:27
  • Run `which npm`. Should tell you is located at `/usr/local/bin/npm`. This location is owned by root. However, your _global packages_ (i.e. the packages you install using `-g` option) are located in the location set by your `.zshrc` at line 1 (Yes, `NPM_PACKAGES=/Users/me/.npm-packages`). To disable your user's `NPM_PACKAGES` just comment this line out. Then, install latest (sudo needed) npm version. Finally, remove comment. No sudo needed after it. – pandres95 Apr 21 '16 at 06:48

1 Answers1

1

Run which npm. You'll figure out npm executable is located at /usr/local/bin/npm. This location is owned by root.

However, your global packages (i.e. the packages you install using -g option) are located in the location set by your .zshrc at line 1 (yes, NPM_PACKAGES=/Users/me/.npm-packages).

To disable your local's NPM_PACKAGES just comment out the related lines in your .zshrc file.

# NPM_PACKAGES=/Users/me/.npm-packages
# NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
# PATH="$NPM_PACKAGES/bin:$PATH"

Then, install latest (sudo needed) npm version.

npm install -g npm@latest

Finally, remove comment marks on .zshrc.

NPM_PACKAGES=/Users/me/.npm-packages
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"

You'll end up with latest npm executable, while installing your global packages in your user folder, so there won't be need of using sudo.

pandres95
  • 183
  • 1
  • 9
  • Hm.. I commented out those NPM/Node lines, did a `sudo install -g npm@latest` and it says it installed fine, but afterward `npm --version` is still 2.11.2. I don't need those paths in my zshrc if it's mucking things up; they're just there as a result of following some setup guide (that apparently has not quite worked out for me) – Damon Apr 23 '16 at 22:59
  • Type `which npm` to find out where this `npm` setup is located. Then, we'll sort this out. – pandres95 May 08 '16 at 05:29