在 EC2 上:未找到 sudo 节点命令,但没有 sudo 的节点可以
我刚刚在新的 EC2 微型实例上安装了 nodejs。
我正常安装了,./configure ->制作->须藤进行安装。
问题:当我在 ec2-user 下运行“node”时,它运行得很好。当我运行“sudo node”时,它失败了。
我发现节点位于:
[ec2-user@XXXX ~]$ whereis node
node: /usr/local/bin/node /usr/local/lib/node
并且当前路径是
[ec2-user@XXXX ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/ec2-user/bin
但是,sudo 路径是
[root@ip-10-112-222-32 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
然后我尝试编辑根路径以包含节点的路径,因此当我以 root 身份登录时“节点”运行 - 但它当我以 ec2-user 身份登录并运行“sudo node”时,仍然无法工作。
我需要这个来正确安装 npm。关于如何在运行“sudo node”时包含节点路径有什么想法吗?
I have just installed nodejs on a new EC2 micro instance.
I installed it normally, ./configure -> make -> sudo make install.
Problem: When I run "node" under ec2-user, it runs perfectly. When I run "sudo node", it fails.
I found out that node is in:
[ec2-user@XXXX ~]$ whereis node
node: /usr/local/bin/node /usr/local/lib/node
and the current path is
[ec2-user@XXXX ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/ec2-user/bin
but, the sudo path is
[root@ip-10-112-222-32 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
then I tried to edit the root PATH to include the paths to node, so "node" runs when I'm logged in as root - but it still won't work when I log in as ec2-user and run "sudo node".
I need this to install npm properfly. Any idea on how to include the node path while running "sudo node"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
是的,这有点烦人,但您可以通过一些链接来修复它:
可能还有更多链接,但这就是我到目前为止遇到的所有内容。缺少 node-waf 将导致某些
npm
安装失败,并显示相当神秘的错误消息。Yes, it is a bit annoying but you can fix it with some links:
There might be more but that is all I have run across so far. Lack of node-waf will cause some
npm
installs to fail with a rather cryptic error message.发生这种情况是因为在 /usr/bin 中找不到节点可执行文件。因此,请按照以下步骤操作:
whereis node
在我的情况下 :
node:/home//.nvm/versions/node/v8.9.4/bin/node
code>为节点创建符号链接:
sudo ln -s /home//.nvm/versions/node/v8.9.4/bin/node /usr/bin/node
完成!
it happens because the node executable is not found in /usr/bin. So follow the steps:
whereis node
in my case:
node: /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node
make a symbolic link for node:
sudo ln -s /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node /usr/bin/node
It's done!
我将
/usr/local/bin
添加到/etc/sudoers
中的secure_path
然后将此行更改
为:
I added
/usr/local/bin
tosecure_path
in/etc/sudoers
Then change this line:
To:
为什么不使用节点的绝对路径?如果您计划使用新贵脚本,那么无论如何它都需要绝对路径。
Why not use the absolute path to node? If you planning to use an upstart script it is going to need an absolute path anyways.
尝试以下操作:
try the following:
您可以使用
which
命令从父级(非 sudo shell)传递到node
可执行文件的完整路径。You could pass full path to
node
executable from parent (non-sudo shell) usingwhich
command.使用“sudo $(哪个节点)”而不是“sudo 节点”怎么样?
How about using "sudo $(which node)" instead of "sudo node" ?
对我来说,它只是将节点文件夹的所有权从 root 更改为 ec2-user (以 ec2-user 身份登录)。
(注意:我在 /var/lib/ 中创建了我的节点文件夹)
然后
应该可以正常工作(当然前提是你已经安装了 npm !)
For me, it worked to just change ownership of node folder from root to ec2-user (logged in as ec2-user).
(Note: I created my node folder in /var/lib/)
Then
should work fine (provided you have installed npm ok of course!)
这是一种不使用符号链接或不需要 root 的方法:
然后我这样做了:
这里讨论不以 root 身份运行节点的好处:
http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/
其内联:
https://github.com/joyent/node/wiki/Installation
Here's an approach that doesn't use symlinks, or require root:
Then I did:
The benefits of not running node as root are discussed here:
http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/
Its inline with:
https://github.com/joyent/node/wiki/Installation
就我而言,安装的 Node 没有 sudo 前缀。因此超级用户无法使用节点,这就是为什么它无法工作
sudo节点服务器
In my case, Node was installed without sudo prefix. So node was unavailable for the superuser that why it is not working
sudo node server
如果您已经安装了节点环境,请将这些命令粘贴到您的实例中,它会将您的节点链接到您的用户目录。您将能够通过 sudo 使用节点。
If you have installed node environment already, paste these command in you r instance and it'll link your node to your user directory. And you will be able to use node with sudo.
以 root 身份输入
,然后执行 标准步骤
Enter as root with
and then do standard steps
这就是我为解决类似问题所做的。注意:我已经通过 snap 安装了节点。
第 1 步:通过 snap 安装节点
第 2 步:查找节点的安装位置
在我的例子中
第 3 步:创建指向节点、npm、npx 和 YARN 的符号链接
最后,所有用户都可以访问节点,甚至 sudo group
This is what I did to solve a similar issue. Note: I had installed node via snap.
Step 1: Install node via snap
Step 2: Find where node has been installed
In my case
Step 3: Create symbolic links to node, npm, npx and yarn
Finally node is accessible for all users, even sudo group
我尝试了上面答案中提到的所有内容,但没有任何效果。可能是因为我对符号链接相关的概念缺乏理解。我通过不使用 nvm 解决了这个问题。
我刚刚创建了一个新的ec2实例,没有安装nvm。相反,我像这样安装了 node 和 npm:
这为我完成了。
I tried everything mentioned in the above answers but nothing worked. Probably because of my lack of understanding of concepts related to sym links. I fixed the issue by not using nvm.
I just created a new ec2 instance and didn't install nvm. Instead I installed node and npm like so:
And this did it for me.
我不知道这是否是正确的方法,但这就是我所做的...
这安装了 npm,我现在可以安装我想要的任何软件包。
I don't know if this is the right way, but this is what i did...
This installed npm, and I can now install any packages I want.