1

I have just installed node and NPM using homebrew, and before that with the package downloaded from the Nodejs website and I still cannot use npm at all without prefixing it with sudo.

When I try npm -v for example, no error is shown, my terminal just waits and waits and waits until finally, a [Process completed] message appears. Why is this and how do I fix it?

I have searched around and tried many things, including the advice in this SO post

Community
  • 1
  • 1
Zander
  • 2,471
  • 3
  • 31
  • 53

3 Answers3

1

Have you added your homebrew location to "$PATH" by adding "export PATH="/usr/local/bin:$PATH" to your bash profile?

Yousef
  • 401
  • 2
  • 8
  • I do actually have it in my $PATH: `/Users/zmartineau/bin:/usr/local/opt/ruby/bin:/opt/local/bin:/opt/local/sbin:/usr/local/lib/node_modules:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin` What else could be the issue? Could something be conflicting? – Zander Jun 18 '14 at 14:04
  • I'm not sure. Have you tried [this](http://howtonode.org/introduction-to-npm). Running ```sudo chown -R $USER /usr/local``` might work. – Yousef Jun 18 '14 at 14:39
  • I have used that in the past but not since installing node through nvm, as instructed from the above answer. – Zander Jun 18 '14 at 16:07
1

The simplest solution I found to make it work for me is to use nvm instead.

https://github.com/creationix/nvm

You probably don't need, or want the feature given by nvm (Switching between Node.js versions) but it is meant to be use in user land and doesn't require access to /usr/lib or the like.

And therefore will provide you what you need without any weird hack.

Aurélien Thieriot
  • 5,853
  • 2
  • 24
  • 25
  • Thanks @Aurelien, I have just removed node from Homebrew and installed via nvm and I still have the same issue. Do you think my problems be coming from my $PATH? See below.. – Zander Jun 18 '14 at 14:24
  • 1
    Can you please give me the results of ```nvm current``` and ```which node``` please? – Aurélien Thieriot Jun 18 '14 at 14:31
  • Sure, `nvm current` returns this: `v0.10.29` and `which node` returns this: /Users/zmartineau/.nvm/v0.10.29/bin/node – Zander Jun 18 '14 at 16:06
  • It's weird because everything seems to be in order there. I mean, the nodejs you use is in your User directory so you don't need sudo at all anymore... – Aurélien Thieriot Jun 18 '14 at 16:14
  • It is weird. From what I have read I have done everything right. I am starting to think that my dotfiles may have something to do with this.. they can be found at https://github.com/mrmartineau/dotfiles (I do not expect you to look through them of course..) Could having incorrect stuff in my PATH or other dotfiles be affecting this? I also found a .npmrc file and I have no idea how it got there.. I will keep persevering and will update the question if I find the solution. – Zander Jun 18 '14 at 16:21
  • .npmrc is used by Npm to store diverse informations like credentials of the npmjs.org repository. – Aurélien Thieriot Jun 18 '14 at 16:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55857/discussion-between-zander-and-aurelien-thieriot). – Zander Jun 18 '14 at 16:31
0

With Aurelien Thierot's help, I figured out what the issue was: my dotfiles had an npm() function that I created to ease installation of npm packages, this had overridden npm itself.

For those that are interested, my fixed npm function for installing packages is:

function npmi() {
    npm install --save-dev "$@"
}
Zander
  • 2,471
  • 3
  • 31
  • 53