npm link and global-ness

1,226 views
Skip to first unread message

Phil Jackson

unread,
Mar 24, 2013, 7:21:43 PM3/24/13
to nod...@googlegroups.com
Hey all,

I'm wondering why `npm link` installs modules in the global node path?
Before I bothered reading the man page I was doing this:

$ npm link ../base

in a project that depends on base. I was just expecting a symlink to the
base package in ./node_modules but instead I get a link to a link in the
global node path.

The problem with this is that for developers who have installed node via
package managers or somewhere under /usr they now need root access to do
an `npm link`. Would a -g option to `npm link` make sense instead of
being global by default?

Cheers,
Phil Jackson
--
Apiaxle http://apiaxle.com - A free, open proxy for your API.

Floby

unread,
Mar 25, 2013, 4:57:39 AM3/25/13
to nod...@googlegroups.com
I compiled my own node, and I do need to have root access for anything global with npm.

Phil Jackson

unread,
Mar 25, 2013, 6:44:07 AM3/25/13
to nod...@googlegroups.com
Hey Floby,

Same here but not everyone does that.

Phil
> --

greelgorke

unread,
Mar 25, 2013, 7:08:47 AM3/25/13
to nod...@googlegroups.com
http://howtonode.org/introduction-to-npm the paragraph about "what no sudo"

Phil Jackson

unread,
Mar 25, 2013, 8:39:38 AM3/25/13
to nod...@googlegroups.com
Hey Greelgorke,

You're missing the point. I'm suggesting that `npm link` shouldn't do
the global thing by default.

Also, if people use package mangers node will end up in /usr/, not
/usr/local.

Cheers,
Phil

greelgorke <greel...@gmail.com> writes:

> http://howtonode.org/introduction-to-npm the paragraph about "what no sudo"
>
> Am Montag, 25. März 2013 11:44:07 UTC+1 schrieb Phil Jackson:
>>
>> Hey Floby,
>>
>> Same here but not everyone does that.
>>
>> Phil
>>

Jérémy Lal

unread,
Mar 25, 2013, 8:53:00 AM3/25/13
to nod...@googlegroups.com, Phil Jackson
"npm link" shouldn't behave like "npm -g link"

NB: this has nothing to do with the way node or npm is installed,
while it is true that node end up in /usr, package managers have npm
configured to global-install modules to /usr/local by default.

J�r�my.




On 25/03/2013 13:39, Phil Jackson wrote:
> Hey Greelgorke,
>
> You're missing the point. I'm suggesting that `npm link` shouldn't do
> the global thing by default.
>
> Also, if people use package mangers node will end up in /usr/, not
> /usr/local.
>
> Cheers,
> Phil
>
> greelgorke <greel...@gmail.com> writes:
>
>> http://howtonode.org/introduction-to-npm the paragraph about "what no sudo"
>>

greelgorke

unread,
Mar 25, 2013, 11:47:49 AM3/25/13
to nod...@googlegroups.com, Phil Jackson, hol...@gmail.com
that's it. tell the package manager to install it in the right place.

the other point, the "local link". you can do this yourself:

ln -s yourLib ./node_modules/yourLib

the problem with it is, that nearly every developer has it's own dir layout. the way npm ln works is the only simple way to be sure where to find the lib you wanna link into your project. i'm sure Isaac can name more arguments for his decision. 

there is another solution: publish your lib, which you wanna link, or pack it and place the tar on restricted server (we did that in one project, jenkins backed, works well)


Am Montag, 25. März 2013 13:53:00 UTC+1 schrieb kapouer:
"npm link" shouldn't behave like "npm -g link"

NB: this has nothing to do with the way node or npm is installed,
while it is true that node end up in /usr, package managers have npm
configured to global-install modules to /usr/local by default.

J�r�my.

Tim Caswell

unread,
Mar 25, 2013, 11:48:51 AM3/25/13
to nod...@googlegroups.com
In your use case, I just manually create a symlink directly and bypass the local stuff:

    cd node_modules
    ln -s ../../base
    cd ..
    npm ls

I use npm link to install a module globally, usually because I'm writing a CLI script and want to test it.

Martin Cooper

unread,
Mar 25, 2013, 10:52:35 PM3/25/13
to nod...@googlegroups.com
On Sun, Mar 24, 2013 at 4:21 PM, Phil Jackson <ph...@apiaxle.com> wrote:
Hey all,

I'm wondering why `npm link` installs modules in the global node path?

When you `npm link`, it effectively creates a global install that can be accessed from any other project. You then create a local reference to that when you use `npm link <package>`. This way, the consumers are decoupled from the source package, via a level of indirection.

The location used for this global install is by default the same location as for global installs of packages probably for convenience. There's no need for yet another location to be found in which to put the links. However, you're free to put these wherever you like, since the location is actually based on the configured `prefix` value, which you can change at will. So you're by no means tied to a location that requires sudo.

--
Martin Cooper

 
Before I bothered reading the man page I was doing this:

    $ npm link ../base

in a project that depends on base. I was just expecting a symlink to the
base package in ./node_modules but instead I get a link to a link in the
global node path.

The problem with this is that for developers who have installed node via
package managers or somewhere under /usr they now need root access to do
an `npm link`. Would a -g option to `npm link` make sense instead of
being global by default?

Cheers,
Phil Jackson
--
Apiaxle http://apiaxle.com - A free, open proxy for your API.

--
--
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

---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages