如何在没有root访问权限的情况下设置npm(节点包管理器)? [英] How do you set up npm (node package manager) without root access?
问题描述
设置npm为root用户是直接的并且工作。除非您必须以root身份运行npm命令(不推荐)。所以我想我会尝试将其设置为非root用户。
Setting npm up as the root user is straighforward and workds. Except you have to run npm commands as root (not recommended). So I thought I'd try setting it up as a non-root user.
根据npm文档,没有root访问权限的非root用户可以通过以下方式设置npm:
According to npm documentation, a non-root user without root access can set up npm by:
- 使用
root
创建.npmrc
文件,binroot
和manroot
指向用户拥有的文件夹。 - 然后运行安装脚本。
- creating a
.npmrc
file withroot
,binroot
, andmanroot
pointing to folders that the user owns. - Then running the install script.
好的。安装很好。
但是节点看不到npm提供的包。
But node can't see the packages provided by npm.
那么我该如何让节点知道npm提供的包吗? (当我以前以root身份安装npm时,我没有做任何事情)。
我可以在节点内设置 require.paths
,或设置 NODE_PATH
环境变量,但是要做什么?
So how do I make node aware of the packages provided by npm? (I didn't have to do anything when I previously installed npm as root).
I can set require.paths
within node, or set the NODE_PATH
environment variable, but to what?
谢谢。
推荐答案
通过一点探索,似乎你可以:
Through a little exploration, it seems you can either:
- 将你的
NODE_PATH
设置为npm的根目录,或者 - 在节点中,调用
require.paths.push('path_to_npm_root')
- set your
NODE_PATH
to whatever npm's root directory is, or - while in node, invoke
require.paths.push('path_to_npm_root')
这篇关于如何在没有root访问权限的情况下设置npm(节点包管理器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!