nvm and npm global installs

9,726 views
Skip to first unread message

Mark Hahn

unread,
Mar 20, 2012, 1:07:38 PM3/20/12
to nodejs
I love nvm and npm.  However, whenever I switch to a new version of node with nvm I have to reinstall all my global npm modules.  Apparently the global modules are stored in the node directory which is created anew.

 Is my setup normal?  Is there a way around this problem?

Tim Caswell

unread,
Mar 20, 2012, 1:29:34 PM3/20/12
to nod...@googlegroups.com
"global" installs install into the node directory.  nvm doesn't upgrade node in-place so each new version of node is a new version.  What you can do it not install npm modules "global"ly.  If you must have them everywhere (like command-line scripts)  install then in $HOME or something and put $HOME/node_modules/.bin in your path.  

On Tue, Mar 20, 2012 at 12:07 PM, Mark Hahn <ma...@hahnca.com> wrote:
I love nvm and npm.  However, whenever I switch to a new version of node with nvm I have to reinstall all my global npm modules.  Apparently the global modules are stored in the node directory which is created anew.

 Is my setup normal?  Is there a way around this problem?

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

C. Mundi

unread,
Mar 20, 2012, 1:31:18 PM3/20/12
to nod...@googlegroups.com

I used to do something like this...

Install global modules to a version-agnostic /use/local/share/node_modules and always export NODE_PATH (or similar).

But what I found is that I ended up chasing breaking changes when updating node anyway.  So I have jumped on the wagon and now the only thing I install globally is express.  And I am so anxious about adapting to express 3...

On Mar 20, 2012 10:08 AM, "Mark Hahn" <ma...@hahnca.com> wrote:
I love nvm and npm.  However, whenever I switch to a new version of node with nvm I have to reinstall all my global npm modules.  Apparently the global modules are stored in the node directory which is created anew.

 Is my setup normal?  Is there a way around this problem?

Mark Hahn

unread,
Mar 20, 2012, 1:33:58 PM3/20/12
to nod...@googlegroups.com
It is not a big deal since I have only 2 or 3 global modules, but I got tripped up when releasing to another server with different nvm location.

I'll take your suggestion to use a common install dir and put it in the path.  I didn't know modules were searched by path.

Tim Caswell

unread,
Mar 20, 2012, 1:40:04 PM3/20/12
to nod...@googlegroups.com
Keep in mind that it's best to not install libraries globally.  It safer to just declare your dependencies in your app's package.json and install them locally using `npm install`.  This prevents a world of headache with version mismatches.  I only use global installs for things like `lessc` `share` (from creationix) and other modules that install command-line scripts.  It's probably best to put them somewhere that other modules won't find like /usr/local/share and just put /usr/local/share/node_modules/.bin in your PATH. (I recommend not using NODE_PATH)

Mark Hahn

unread,
Mar 20, 2012, 2:18:23 PM3/20/12
to nod...@googlegroups.com
Don't I have to install coffee-script globally to be able to use the `coffee` as a command anywhere?  Same with node-dev, node-inspector, etc.

Tim Caswell

unread,
Mar 20, 2012, 2:48:05 PM3/20/12
to nod...@googlegroups.com
On Tue, Mar 20, 2012 at 1:18 PM, Mark Hahn <ma...@hahnca.com> wrote:
Don't I have to install coffee-script globally to be able to use the `coffee` as a command anywhere?  Same with node-dev, node-inspector, etc.

Right, they have to be installed somewhere in your $PATH.  This doesn't have to be the "global" place, but it does work out of the box since it uses the same bin folder as node itself.  non-global installs put the executables in ./node_modules/.bin/, "global" installs put it in $PREFIX/bin/ where $PREFIX is where you installed node to. (nvm uses a custom $PREFIX per node version and puts $PREFIX/bin in your path)

Mark Hahn

unread,
Mar 20, 2012, 2:58:51 PM3/20/12
to nod...@googlegroups.com
Thx a lot.  Should I save this message or is it documented somewhere i can save a link to?

Isaac Schlueter

unread,
Mar 20, 2012, 7:16:54 PM3/20/12
to nod...@googlegroups.com
You can work around this issue in nave using named environments.

```
nave use foo 0.6.9
# installs node v0.6.9, links it into a named env "foo"
npm install -g glob
npm ls -g
# shows glob there.

# work work work
# time goes by
# from the outside:

nave use foo 0.6.13
# upgrades foo to use 0.6.13 instead
# enters foo
npm ls -g
# glob is still there!
# compiled modules may be broken and require a `npm rebuild -g` though
```

Reply all
Reply to author
Forward
0 new messages