[英]NPM not recognizing any command
ok when i run : 好的,当我跑步时:
npm install nodemon -g
it returns : 它返回:
/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)
or 要么
npm install forever -g
or any node install i then can't access the command afterwards: 或任何节点安装后,我将无法再访问该命令:
nodemon: command not found
but i can run them if i reference the file directly as is the case of forever: 但是如果我像永久一样直接引用文件,则可以运行它们:
/home/ubuntu/.node/lib/node_modules/forever/bin/forever server/app.js &
works just fine.... why? 效果很好...为什么? fixes? 修复?
profile... 轮廓...
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
Commands! 命令! : :
echo $PATH:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
And 和
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
Weird give me this on rersart now: 很奇怪,现在就给我发短信:
-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
your node install is whacked 您的节点安装被重击
Below are the steps to install Node.js from source (OSX/linux) 以下是从源代码(OSX / linux)安装Node.js的步骤
NOTE - this installs Node.js which gives you both node as well as npm, they come together per release. 注意-这将安装Node.js,它为您同时提供节点和npm,它们在每个版本中都结合在一起。
to start fresh remove prior node and npm installs as well as these : 要开始全新删除先前的节点和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
download source from : https://nodejs.org/en/download/stable/ 从以下位置下载源: https : //nodejs.org/en/download/stable/
or if you need a particular release https://nodejs.org/download/release 或者如果您需要特定的版本https://nodejs.org/download/release
Once you have expanded then cd into the source code dir 展开后,将cd插入源代码目录
cd node-v5.5.0 # or whatever current name is
You may/should issue all following cmds as yourself NOT root (sudo) 您可能/应该以自己不root的身份发出以下所有cmds(sudo)
Pick one of these NODE_PARENT locations to define where node gets installed into : 选择以下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
which puts it into dir defined by above --prefix 将其放入上述--prefix定义的目录中
when you use syntax : npm install -g some_cool_module the -g for global installs it into dir $NODE_PATH and not your $PWD 当您使用语法时:npm install -g some_cool_module -g for global将其安装到目录$ NODE_PATH中,而不是$ PWD中
IMPORTANT - put above three export xxx=yyy commands into your ~/.bashrc or some such to persist these environment variable changes 重要-将以上三个export xxx = yyy命令放到〜/ .bashrc或类似的命令中,以保留这些环境变量更改
Add /home/ubuntu/.node/bin
to your PATH. 将/home/ubuntu/.node/bin
添加到PATH。
eg in your .profile or .bashrc file, add: 例如,在您的.profile或.bashrc文件中,添加:
export PATH = /home/ubuntu/.node/bin:$PATH
* EDIT * *编辑*
I would not put the udpated path inside that if
statement, as they're independent facts (whether or not you have a home bin and whether or not you're setting your node module path). 我不会将udpated路径放入该if
语句中,因为它们是独立的事实(您是否有家庭垃圾箱以及是否要设置节点模块路径)。
Also, make sure you reloaded your .profile
after editing it: 另外,请确保您在编辑.profile
后重新加载它:
source /home/ubuntu/.profile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.