尝试为 Node.js 安装 npm 时出错

发布于 2024-12-08 16:26:13 字数 3512 浏览 0 评论 0原文

我正在尝试学习 Node.js,但在安装 NPM(节点包管理器)时遇到了一些问题。我很确定这要么是权限问题,要么是文件夹问题……请注意,我刚刚购买了一台 Mac(我一生都在使用 Windows),而且我对 Mac 终端非常不熟悉。

好的,我使用 NPM 的一行安装: curl http://npmjs.org/install.sh | sh ,我收到错误...

All clean!
! [ -d .git ] || git submodule update --init --recursive
node cli.js rm npm -g -f
node cli.js install -g -f
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.0.0
npm ERR! command "node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
make: *** [install] Error 1
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.0.0
npm ERR! command "/usr/local/bin/node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
It failed

这里显然有一个文件夹问题,也许我安装在错误的位置,当我尝试找出我的节点路径时,我的节点文件夹位于 Users/Mike/node使用 NODE_PATH 变量我收到以下错误:

Michaels-MacBook-Pro:~ Mike$ node node/NODE_PATH  

node.js:203
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module '/Users/Mike/node/NODE_PATH'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Array.<anonymous> (module.js:470:10)
    at EventEmitter._tickCallback (node.js:195:26)

有人可以告诉我我做错了什么吗?我是否需要像这样添加节点路径:

$ export PATH=/path/to/node/0.n.y/bin:${PATH}
$ curl http://npmjs.org/install.sh | sh

或者我自己感到困惑吗?

I'm having a stab at learning Node.js and I'm having a few issues when installing NPM (Node Package Manager). I'm pretty sure it's either a permissions thing or folder thing... please note that I've just purchased a Mac (I've used Windows all my life) and I'm pretty unfamiliar with the Mac terminal.

Okay, I went to use the one line install for NPM: curl http://npmjs.org/install.sh | sh and I got an error...

All clean!
! [ -d .git ] || git submodule update --init --recursive
node cli.js rm npm -g -f
node cli.js install -g -f
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.0.0
npm ERR! command "node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
make: *** [install] Error 1
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.0.0
npm ERR! command "/usr/local/bin/node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
It failed

there's obviously a folder issue here, perhaps I'm installing in the wrong place, my node folder is at Users/Mike/node, when I try and find out my node path variable using NODE_PATH I get the following error:

Michaels-MacBook-Pro:~ Mike$ node node/NODE_PATH  

node.js:203
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module '/Users/Mike/node/NODE_PATH'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Array.<anonymous> (module.js:470:10)
    at EventEmitter._tickCallback (node.js:195:26)

Can someone please tell me what I'm doing wrong? Do I need to add the node path like such:

$ export PATH=/path/to/node/0.n.y/bin:${PATH}
$ curl http://npmjs.org/install.sh | sh

Or am I confusing myself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那伤。 2024-12-15 16:26:13

/usr/local 上的权限要求您使用 sudo 安装 NPM,或更改您的权限。在这三个选项中,我推荐第三个选项

选项#1:使用 sudo

(请注意,NPM 的创建者 建议不要使用此方法

curl http://npmjs.org/install.sh | sudo sh

选项#2:更改权限

sudo chmod g+rwx /usr/local
sudo chgrp admin /usr/local

选项#3:使用 Homebrew

我推荐 安装 Homebrew 来管理在 OS X 上安装 *nix 工具(我会远离 MacPortsFink)。安装 Homebrew 将设置 /usr/local 的权限,以便您无需 sudo 即可对其进行写入。然后就可以通过Homebrew安装Node,然后正常安装NPM:

brew install node --without-npm
curl http://npmjs.org/install.sh | sh

The permissions on /usr/local require you to use sudo to install NPM, or change your permissions. Of these three, I recommend the third option.

Option #1: Use sudo

(Note that the the creator of NPM advises against using this method)

curl http://npmjs.org/install.sh | sudo sh

Option #2: Change permissions

sudo chmod g+rwx /usr/local
sudo chgrp admin /usr/local

Option #3: Use Homebrew

I recommend installing Homebrew to manage installing *nix tools on OS X (I'd stay away from MacPorts & Fink). Installing Homebrew will set the permissions for /usr/local so you can write to it without sudo. You can then install Node via Homebrew, and then install NPM normally:

brew install node --without-npm
curl http://npmjs.org/install.sh | sh
旧话新听 2024-12-15 16:26:13

使用curl http://npmjs.org/install.sh | sudo sh。

编辑:您正在使用node -v v0.5.9-pre,它非常不稳定。使用0.4.12,最新的稳定版本。

Use curl http://npmjs.org/install.sh | sudo sh.

Edit: You're using node -v v0.5.9-pre, which is very unstable. Use 0.4.12, the latest stable version.

不必了 2024-12-15 16:26:13

如果您使用的是 Windows,则需要执行一些步骤,1)创建一个名为 package.json

{
“姓名”:“你好”
,“版本”:“0.0.1”
,“依赖项”:{
“表达”: ”*”
}
}
其中 hello 是包的名称,* 表示依赖项的最新版本

2) 将代码复制到项目目录并运行以下命令

npm install

if you are using windows , it takes some steps , 1) create a file called package.json

{
"name": "hello"
, "version": "0.0.1"
, "dependencies": {
"express": "*"
}
}
where hello is the name of the package and * means the latest version of your dependency

2) code to you project directory and run the following command

npm install

不寐倦长更 2024-12-15 16:26:13

作为 OSX 上方法 #3 的更新,现在正确的命令是:

brew install node --without-npm
curl https://www.npmjs.org/install.sh | sh

As update for the method #3 on OSX the correct command now is:

brew install node --without-npm
curl https://www.npmjs.org/install.sh | sh
迷荒 2024-12-15 16:26:13

选项#4:

将节点安装到需要它的用户本地。

我应该澄清,出于我的目的,我需要 npm 在运行 Bamboo 的 OSX 服务器上安装 appium 来进行集成测试。我只有 macports 可用,而不是安装 homebrew 来管理一个软件包,我决定从源代码构建它并将其安装在本地的ubab用户中。这使我们能够以 Bamboo 用户的身份运行 Appium,并以非特权用户的身份在 Bamboo 上运行 Appium 测试。

Tom Novelli 的本指南 结束怎么做。基本要点是:

# Make the dir to hold the installation of node
cd
mkdir ./local
mkdir sources
# Tell npm about your new non-default directories
vi .npmrc 
cd sources
# Get node and do the typical source install procedure
wget http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz
tar xf node-v0.10.29.tar.gz
cd node-v8.10.29/
# Important part is the --prefix
./configure --prefix=~/.local
make
make install
# Make a link so node doesn't get confused
cd
ln -s .local/lib/node_modules .node_modules
# Edit PATH to include ~/.local
vi .bashrc

.npmrc

root =    /home/YOUR-USERNAME/.local/lib/node_modules
binroot = /home/YOUR-USERNAME/.local/bin
manroot = /home/YOUR-USERNAME/.local/share/man

.bashrc 或 .profile 或您喜欢设置路径的任何位置

export PATH=$HOME/.local/bin:$PATH

有用链接

.npmrc 手册页很有用。

为了以防万一,这里有一个指向节点源的链接。

Option #4:

Install node local to the user that needs it.

I should clarify for my purposes I needed npm to install appium on an OSX server running Bamboo for our integrated testing. I only had macports available and rather than installing homebrew to manage just the one package I decided to build it from source and install it local to the bamboo user. Which allowed us to run appium as the bamboo user and made it possible to run our appium tests on Bamboo as a not very privileged user.

This guide from Tom Novelli goes over how to do it. The basic gist is:

# Make the dir to hold the installation of node
cd
mkdir ./local
mkdir sources
# Tell npm about your new non-default directories
vi .npmrc 
cd sources
# Get node and do the typical source install procedure
wget http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz
tar xf node-v0.10.29.tar.gz
cd node-v8.10.29/
# Important part is the --prefix
./configure --prefix=~/.local
make
make install
# Make a link so node doesn't get confused
cd
ln -s .local/lib/node_modules .node_modules
# Edit PATH to include ~/.local
vi .bashrc

.npmrc

root =    /home/YOUR-USERNAME/.local/lib/node_modules
binroot = /home/YOUR-USERNAME/.local/bin
manroot = /home/YOUR-USERNAME/.local/share/man

.bashrc OR .profile OR whereever you like setting your path

export PATH=$HOME/.local/bin:$PATH

Useful Links

The .npmrc man page useful.

And just in case here's a link to node source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文