无法运行全局安装的节点模块

时间:2014-05-03 10:18:50

标签: node.js ubuntu npm

我已经在VM中安装了Ubuntu 14.04。使用软件中心安装了nodejs。

suman@ubuntu:~$ node --version
v0.10.26
suman@ubuntu:~$ npm --version
1.4.3

下面的npm配置

suman@ubuntu:~$ npm config ls -l
; cli configs
long = true
registry = "https://registry.npmjs.org/"

; userconfig /home/suman/.npmrc
prefix = "/.node"

; default values
always-auth = false
bin-links = true
browser = null
ca = null
cache = "/home/suman/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cert = null
color = true
depth = null
description = true
dev = false
editor = "vi"
email = ""
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
global = false
globalconfig = "/usr/local/etc/npmrc"
globalignorefile = "/usr/local/etc/npmignore"
group = 1000
heading = "npm"
https-proxy = null
ignore-scripts = false
init-module = "/home/suman/.npm-init.js"
init.author.email = ""
init.author.name = ""
init.author.url = ""
init.license = "ISC"
json = false
key = null
link = false
local-address = undefined
loglevel = "http"
; long = false (overridden)
message = "%s"
node-version = "v0.10.26"
npat = false
onload-script = false
optional = true
parseable = false
; prefix = "/usr" (overridden)
production = false
proprietary-attribs = true
proxy = null
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = false
save-bundle = false
save-dev = false
save-optional = false
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "/bin/bash"
shrinkwrap = true
sign-git-tag = false
strict-ssl = true
tag = "latest"
tmp = "/home/suman/tmp"
umask = 18
unicode = true
unsafe-perm = true
usage = false
user = 0
user-agent = "node/v0.10.26 linux x64"
userconfig = "/home/suman/.npmrc"
username = ""
version = false
versions = false
viewer = "man"

我使用npm install -g grunt-cli bower安装了grunt-cli,bower等 但是我无法将它们作为shell命令执行。

苏曼

1 个答案:

答案 0 :(得分:1)

最好避免在安装nodejs软件包时发出sudo,因为节点永远不应该以root身份运行(与HTTPD不以root用户身份运行的原因相同)。始终安装并运行node和npm作为您自己。重新开始在ubuntu上重新安装nodejs和npm(在nodejs git下面给你npm)(特别是在发出各种sudo命令之后):

删除或重命名这些目录:(由npm创建,如果您使用sudo,通常由root拥有)

sudo mv ~yourUnixId/.npm ~yourUnixId/ignore.npm
sudo mv ~yourUnixId/tmp  ~yourUnixId/ignore_tmp    
sudo mv ~yourUnixId/.npmrc  ~yourUnixId/ignore_.npmrc
sudo mv ~yourUnixId/.npm-init.js  ~yourUnixId/ignore_.npm-init.js

http://nodejs.org/download/

下载源代码
cd /path/to/downloaded/src/

./configure   --prefix=${HOME}/bin/nodejs
make
make install  #  will install into above prefix dir

将你的PATH抬起来寻找新的可执行文件

export PATH=${HOME}/bin/nodejs/bin:$PATH:.

这定义了在发出npm命令时到达nodejs模块的路径:

export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules

继续发出npm install AS YOURSELF NOT sudo并将-g标志作为

npm install someCoolModule -g

自己执行节点:

node myNode.js

你现在应该全力以赴 - 享受