bash: pm2: 命令未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40799533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash: pm2: command not found
提问by Kamil
I can't run pm2 on ubuntu box. I'm not sure what's the problem. The pm2 is installed globally.
我无法在 ubuntu 机器上运行 pm2。我不确定是什么问题。pm2 是全局安装的。
npm list -g --depth=0
/opt/nodejs/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
But I still get
但我仍然得到
pm2
-bash: pm2: command not found
if I run other app
如果我运行其他应用程序
userdown
Starting Script is not provided
versions
版本
node v4.5.0
npm v2.15.9
log from installation:
安装日志:
sudo npm install pm2 -g
npm WARN optional dep failed, continuing [email protected]
/opt/nodejs/bin/pm2 -> /opt/nodejs/lib/node_modules/pm2/bin/pm2
/opt/nodejs/bin/rundev -> /opt/nodejs/lib/node_modules/pm2/bin/rundev
/opt/nodejs/bin/pm2-dev -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-dev
/opt/nodejs/bin/pm2-docker -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-docker
[email protected] /opt/nodejs/lib/node_modules/pm2
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected]
kamil@vps2:~$ pm2
-bash: pm2: command not found
ubuntu version:
Ubuntu 版本:
uname -a
Linux vps2 2.6.32-042stab111.11 #1 SMP Tue Sep 1 18:19:12 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
回答by Kamil
Ok got answer myself. I check what happens for
好的,我自己回答了。我检查会发生什么
whereis pm2
pm2: /opt/nodejs/bin/pm2
then I checked
然后我检查了
whereis userdown
userdown: /usr/bin/userdown /usr/bin/X11/userdown /opt/nodejs/bin/userdown
hmm in /usr/bin.... So I did
嗯在 /usr/bin .... 所以我做了
sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2
and it works :)
它有效:)
回答by Luís Brito
The problem is that you are running NPM as sudo, so you will only be able to access it using:
问题是您以 sudo 身份运行 NPM,因此您只能使用以下方式访问它:
sudo pm2 start server.js
Install without sudo, you may even install without the -g
flag and call it directly from node_modules
directory. This may be useful if you do not have root (admin) privileges in the machine you're working on.
无需 sudo 安装,您甚至可以在没有-g
标志的情况下安装并直接从node_modules
目录中调用它。如果您在正在使用的机器上没有 root(管理员)权限,这可能很有用。
npm install pm2
./node_modules/.bin/pm2 start server.js
回答by servercharlie
Follow the proper nodejs isntallation, npm permission fixes and npm global packages tweaks:
遵循适当的 nodejs 安装、npm 权限修复和 npm 全局包调整:
@ https://gist.github.com/servercharlie/9a7e0d0e1645b4c6fbfe5de566fcf1ca
@ https://gist.github.com/servercharlie/9a7e0d0e1645b4c6fbfe5de566fcf1ca
Your script needs to do some thing that requires root privilege? (ie: you're getting an error on using port 80)
你的脚本需要做一些需要 root 权限的事情吗?(即:您在使用端口 80 时遇到错误)
[wrong] - trying to run w/ sudo
[错误] - 尝试使用 sudo 运行
[correct] - login as root "sudo su" then do pm2 start app.js --name "whatever" --watch
[正确] - 以 root 身份登录“sudo su”然后执行 pm2 start app.js --name "whatever" --watch
that does it, no need to configure any bashrc or profile files.
这样做,无需配置任何 bashrc 或配置文件。
extra: worried about your app doing crazy shit? (ie, since it's executed as root, the script can use nodejs's exec and do some crazy stuff.)
额外:担心你的应用做疯狂的事?(即,由于它以 root 身份执行,脚本可以使用 nodejs 的 exec 并做一些疯狂的事情。)
hence. do this: do the root-stuff first with your script, then lower your privilege after some timeout:
因此。这样做:首先用你的脚本做root-stuff,然后在一些超时后降低你的权限:
// i use port 80 first.. at this point the script's uid is ROOT.
// 我首先使用端口 80.. 此时脚本的 uid 是 ROOT。
app.listen(80);
应用程序听(80);
// after 2 seconds we switch to uid AZUREUSER, which obviously isn't root anymore.
// 2 秒后我们切换到 uid AZUREUSER,这显然不再是 root。
setTimeout(function(){
设置超时(功能(){
process.setuid("azureuser");
process.setuid("azureuser");
}, 2000);
}, 2000);
回答by Shree Prakash
In my scenario I wrote a shell script that was triggered by jenkins build and
在我的场景中,我编写了一个由 jenkins build 和
I fixed using following link
我使用以下链接修复