Zander
Zander

Reputation: 2684

Unable to use NPM without sudo

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

Upvotes: 1

Views: 1093

Answers (3)

Zander
Zander

Reputation: 2684

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 "$@"
}

Upvotes: 0

Aurélien Thieriot
Aurélien Thieriot

Reputation: 5923

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.

Upvotes: 1

Yousef
Yousef

Reputation: 401

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

Upvotes: 1

Related Questions