NPM不承认任何命令

好吧,当我运行:

npm install nodemon -g 

它返回:

 /home/ubuntu/.node/bin/nodemon -> /home/ubuntu/.node/lib/node_modules/nodemon/bin/nodemon.js nodemon@1.2.1 /home/ubuntu/.node/lib/node_modules/nodemon ├── minimatch@0.3.0 (sigmund@1.0.0, lru-cache@2.5.0) ├── ps-tree@0.0.3 (event-stream@0.5.3) └── update-notifier@0.1.10 (semver@2.3.2, chalk@0.4.0, configstore@0.3.1, request@2.49.0) 

要么

 npm install forever -g 

或者任何节点安装我然后不能访问命令后:

 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 

你的节点安装被打断了

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

注 – 这会安装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 

从以下url下载源代码: https : //nodejs.org/en/download/stable/
或者如果你需要一个特定的版本https://nodejs.org/download/release

一旦你扩大了,然后cd到源代码目录

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

你可能/应该发出所有跟随的cmds作为你自己不root(sudo)

select其中一个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 

把它放到上面定义的dir中–prefix

当你使用语法:npm install -g some_cool_module -g for global将它安装到dir $ NODE_PATH而不是你的$ PWD

重要的 – 把上面的三个出口xxx = yyy命令放到你的〜/ .bashrc或者其他一些这样的地方来坚持这些环境variables的改变

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

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

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

*编辑*

我不会把这个udpatedpath放在if语句中,因为它们是独立的事实(不pipe你是否有一个home bin,也不pipe你是否设置你的节点模块path)。

另外,确保在编辑之后重新载入.profile

 source /home/ubuntu/.profile