NPM 模块不会在没有 sudo 的情况下全局安装 [英] NPM modules won't install globally without sudo

查看:29
本文介绍了NPM 模块不会在没有 sudo 的情况下全局安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚重新安装了 Ubuntu 12.04 LTS,然后我先执行了这些步骤:

  1. 使用以下脚本通过包管理器安装节点

  1. Installed Node via package manager with the following script

sudo apt-get update

sudo apt-get install python-software-properties python g++ make

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get install nodejs

  • 尝试全局安装 yeoman, express, n, yeoman 的生成器,都返回同样的错误

  • Tried to install yeoman, express, n, yeoman's generators globally and all of them returned the same error

    npm 错误!错误:EACCES,符号链接 '../lib/node_modules/n/bin/n'

    npm ERR! Error: EACCES, symlink '../lib/node_modules/n/bin/n'

    npm 错误!{ [错误:EACCES,符号链接'../lib/node_modules/n/bin/n'] errno:3,代码:'EACCES',路径:'../lib/node_modules/n/bin/n' }

    npm ERR! { [Error: EACCES, symlink '../lib/node_modules/n/bin/n'] errno: 3, code: 'EACCES', path: '../lib/node_modules/n/bin/n' }

    npm 错误!

    npm 错误!请尝试以 root/管理员身份再次运行此命令.

    npm ERR! Please try running this command again as root/Administrator.

    npm 错误!系统 Linux 3.8.0-29-generic

    npm ERR! System Linux 3.8.0-29-generic

    npm 错误!命令/usr/bin/node"/usr/bin/npm"安装"-g"-d"n"

    npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "-d" "n"

    npm 错误!cwd/home/heberlz

    npm ERR! cwd /home/heberlz

    npm 错误!节点 -v v0.10.20

    npm ERR! node -v v0.10.20

    npm 错误!npm -v 1.3.11

    npm ERR! npm -v 1.3.11

    npm 错误!路径../lib/node_modules/n/bin/n

    npm ERR! path ../lib/node_modules/n/bin/n

    npm 错误!代码EACCES

    npm ERR! code EACCES

    npm 错误!错误号 3

    npm ERR! errno 3

    npm 错误!堆栈错误:EACCES,符号链接 '../lib/node_modules/n/bin/n'

    npm ERR! stack Error: EACCES, symlink '../lib/node_modules/n/bin/n'

    npm 错误!

    npm 错误!可以在以下位置找到其他日志记录详细信息:

    npm ERR! Additional logging details can be found in:

    npm 错误!/home/heberlz/npm-debug.log

    npm ERR! /home/heberlz/npm-debug.log

    npm 错误!代码不正确 0

    npm ERR! not ok code 0

  • 递归地收回以下文件夹的所有权 ~/.npm、/usr/lib/node、/usr/lib/node_modules 和以下符号链接/usr/bin/node,/usr/bin/nodejs 完全没有成功

  • Reclaimed ownership of the following folders recursively ~/.npm, /usr/lib/node, /usr/lib/node_modules, and of the following symlinks /usr/bin/node, /usr/bin/nodejs with absolutely no success

    我需要在没有 sudo 的情况下安装 yeoman 及其生成器,以免以后遇到麻烦 :(

    I need to install yeoman and its generators without sudo not to be in trouble later on :(

    推荐答案

    Ubuntu 12.04 并使用 Chris Lea 的 PPA 为我安装以下作品:

    Ubuntu 12.04 and using Chris Lea's PPA for install the following works for me:

    npm config set prefix '~/.npm-packages'
    

    并将 $HOME/.npm-packages/bin 添加到 $PATH

    and adding $HOME/.npm-packages/bin to $PATH

    附加到 .bashrc

    export PATH="$PATH:$HOME/.npm-packages/bin"
    

    参见@passy 的https://stackoverflow.com/a/18277225

    这篇关于NPM 模块不会在没有 sudo 的情况下全局安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆