2014-12-06 90 views
1

确定当我运行:NPM不承认任何命令

npm install nodemon -g 

它返回:

/home/ubuntu/.node/bin/nodemon -> /home/ubuntu/.node/lib/node_modules/nodemon/bin/nodemon.js 
[email protected] /home/ubuntu/.node/lib/node_modules/nodemon 
├── [email protected] ([email protected], [email protected]) 
├── [email protected] ([email protected]) 
└── [email protected] ([email protected], [email protected], [email protected], [email protected]) 

npm install forever -g 

或任何节点安装i,那么不能访问命令之后:

nodemon: command not found 

,但如果我直接引用文件是永远的情况下,我可以运行它们:

/home/ubuntu/.node/lib/node_modules/forever/bin/forever server/app.js & 

作品就好了.... 为什么呢? 修复?

资料...

GNU nano 2.2.6       File: /home/ubuntu/.profile                

# ~/.profile: executed by the command interpreter for login shells. 
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login 
# exists. 
# see /usr/share/doc/bash/examples/startup-files for examples. 
# the files are located in the bash-doc package. 

# the default umask is set in /etc/profile; for setting the umask 
# for ssh logins, install and configure the libpam-umask package. 
#umask 022 

# if running bash 
if [ -n "$BASH_VERSION" ]; then 
    # include .bashrc if it exists 
    if [ -f "$HOME/.bashrc" ]; then 
     . "$HOME/.bashrc" 
    fi 
fi 

# set PATH so it includes user's private bin if it exists 
if [ -d "$HOME/bin" ] ; then 
    PATH="$HOME/bin:$PATH" 
    export PATH = /home/ubuntu/.node/bin:$PATH 

fi 

命令! :

echo $PATH: 
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

而且

ls -la 
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec 6 14:42 . 
drwxrwxr-x 4 ubuntu ubuntu 4096 Dec 6 12:24 .. 
lrwxrwxrwx 1 ubuntu ubuntu 39 Dec 6 14:42 forever -> ../lib/node_modules/forever/bin/forever 
lrwxrwxrwx 1 ubuntu ubuntu 42 Dec 6 14:19 nodemon -> ../lib/node_modules/nodemon/bin/nodemon.js 

奇怪,现在给我这个上rersart:

-bash: export: `=': not a valid identifier 
-bash: export: `/home/ubuntu/.node/bin:/home/ubuntu/.node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier 
+2

显然,npm安装二进制文件的路径不在你的PATH中。 – poke 2014-12-06 14:31:09

+0

是的,我一直在阅读,我需要编辑bashrc什么的,但有点不确定如何去做。 – vimes1984 2014-12-06 14:34:37

回答

0

添加/home/ubuntu/.node/bin到您的PATH。

例如在.profile或.bashrc文件,添加:

export PATH = /home/ubuntu/.node/bin:$PATH 

*编辑*

我不会把udpated路径if语句内,因为他们是独立的事实(不管是不是你有一个家庭垃圾箱,无论你是否设置你的节点模块路径)。

另外,确保你在编辑之后重新加载您.profile

​​
+0

这不起作用... 更新答案与我的贝斯和简介 – vimes1984 2014-12-06 14:40:00

+0

你能'回声那台机器上的$ PATH'来验证它是在那里设置的?还有'ls -la/home/ubuntu/.node/bin'。也可能是许可问题;我假设你是以用户'ubuntu'登录的? – Paul 2014-12-06 15:02:10

+0

是我登录作为Ubuntu的问题更新... – vimes1984 2014-12-06 15:05:35

1

您的节点安装是疲惫不堪

下面是从源代码安装Node.js的步骤(OSX/Linux)的

注意 - 这会安装Node.js,它可以为您提供节点以及每个版本的npm, 。

从头开始删除之前节点和NPM安装以及这些:

sudo mv ~/.npmrc ~/.npmrc_ignore 
sudo mv ~/.npm ~/.npm_ignore 
sudo mv ~/tmp ~/tmp_ignore 
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore 

下载源来自:https://nodejs.org/en/download/stable/
或者如果你需要一个特定版本https://nodejs.org/download/release

一旦再扩展CD进入源代码目录

cd node-v5.5.0 # or whatever current name is 

你可能会d问题的所有以下CMDS如己NOT根(须藤)

接这些NODE_PARENT位置之一,以限定其中节点被安装成:

export NODE_PARENT=/some/desired/install/path_goes_here 
export NODE_PARENT=/usr/local/bin/nodejs # use this ONLY if you MUST install as root (sudo) 
export NODE_PARENT=${HOME}/nodejs-v0.10.33 # Recommended - its owned by you NOT root 

export PATH=${NODE_PARENT}/bin:${PATH}  # so executables are found 
export NODE_PATH=${NODE_PARENT}/lib/node_modules # so node can find its modules dir 

./configure --prefix=${NODE_PARENT} 

make 
make install 

其中将其放入目录由上述--prefix

定义

当您使用语法:NPM安装-g some_cool_module 全球的-g安装成DIR $ NODE_PATH,而不是你的$ PWD

重要 - 上述三个出口放XXX = YYY 合作命令到你的〜/ .bashrc或一些这样来坚持这些环境变量的变化