sindresorhus / guides

A collection of succinct guides - Public Domain
2.47k stars 458 forks source link

PATH not updated in npm-global-without-sudo settings #29

Closed dmitriz closed 8 years ago

dmitriz commented 8 years ago

On my Mac OS 10.10.5 the settings from https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md still did not update the path, so I had to add this to my .bash_profile:

export PATH=~/.npm-packages/bin:$PATH

dmitriz commented 8 years ago

I have investigated it further and the following summarised entry updates both PATH and NODE_PATH work:

# Move global node modules to local directory                                                                                                                                  
NPM_PACKAGES=~/.npm-packages
export NODE_PATH=$NPM_PACKAGES/lib/node_modules:$NODE_PATH
export PATH=$PATH:$NPM_PACKAGES/bin

PATH still seems to be updated without export but NODE_PATH doesn't.

dmitriz commented 8 years ago

The setup actually seems to work without NODE_PATH, I could not find any documentation on it.

It looks like the setting in .npmrc is enough for Node to know where to install global packages, and no further NODE_PATH setting seems to be needed. At least it works on my machine like that.

sindresorhus commented 8 years ago

You're right. I've done some tweaks. PATH doesn't need to be exported as it already is in all shells.

Rowno commented 8 years ago

You can also remove step 2 if you rename NPM_PACKAGES to NPM_CONFIG_PREFIX. :wink:

sindresorhus commented 8 years ago

@Rowno I know. It was deliberate. I think it's better to keep it in .npmrc so it will work when npm is run outside the shell too.

elpiel commented 8 years ago

I have another question. I successfully changed my dir, but when I install latest npm package it saves it in the Profile dir ~/.npm-packages and the terminal finds the old version which is still located in /usr/bin/?

ghost commented 6 years ago

@elpiel Did you solve your issue? I have the same.

elpiel commented 6 years ago

I'm not using MacOS anumore @saulius-spiridonas-ht . Problem solved 😹