我跑的时候好的:
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
或任何节点安装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
答案 0 :(得分:1)
您的节点安装受到了打击
以下是从源代码(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
从https://nodejs.org/en/download/stable/下载源代码 或者如果您需要特定版本https://nodejs.org/download/release
一旦你扩展了cd,然后进入源代码dir
cd node-v5.5.0 # or whatever current name is
您可能/应该发出以下所有cmd,因为您不是root(sudo)
选择其中一个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 install -g some_cool_module -g for global将它安装到dir $ NODE_PATH而不是你的$ PWD
重要 - 将以上三个导出xxx = yyy 命令到你的〜/ .bashrc或其他一些来保持这些环境变量的变化
答案 1 :(得分:0)
将/home/ubuntu/.node/bin
添加到您的路径中。
e.g。在.profile或.bashrc文件中,添加:
export PATH = /home/ubuntu/.node/bin:$PATH
*编辑*
我不会将udpated路径放在if
语句中,因为它们是独立的事实(无论你是否有一个home bin以及你是否正在设置节点模块路径)。
此外,请确保在编辑后重新加载.profile
:
source /home/ubuntu/.profile