6

I installed node.js according to this article .

For this i downloaded a precompiled node.js arm-pi distributition and unzipped it

cd /opt
sudo wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz

After that i added the path to which node.js was unpacked tu the /.profile

export PATH=$PATH:/opt/node-v0.10.28-linux-arm-pi/bin

now

node --version

return 0.10.28

but when i run

sudo node --version

node isn't found.

I also tried to add the export path code to /root/.profile and restarted the node. But still node isn't found.

PS: is it right t hat 0.10.28 is the most current version supported for raspberrian, as there is no neweer *-linux-arm distribution?

Later on i Found that i could also install node.js with apt-get.

Getting NPM installed on Raspberry Pi (Wheezy Image)

Is that right ? what is the preferred way and whould this have solved the problem, that sudo doens't now node?

Any hints ?

Answers to the questions in the Comments:

pi@PiDuino /be/Serial $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/node-v0.10.28-linux-arm-pi/bin

pi@PiDuino /be/Serial $ sudo echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/node-v0.10.28-linux-arm-pi/bin

runnning

sudo /opt/node-v0.10.28-linux-arm-pi/bin/node

works

Boas Enkler
  • 215
  • 3
  • 7

2 Answers2

5

I definitely think this has to do with your PATH. An easy way to check this is to compare the output of echo $PATH with the output of sudo echo $PATH. If the node.js directory is present in the first but not in the second, there is something going on with your PATH setup.

The reason for this is that sudo does not actually load the root profile. Rather, it tries to create a "safe" profile for one command only. If you cat the /etc/sudoers-file (sudo cat /etc/sudoers) you will see the "secure_path" being used in a sudo context. You can edit this - BUT ...

This brings me to another question: Why on earth would you like to run node.js with root privileges? JavaScript is - arguably and due to many cool features - the most insecure language that is in wide spread use. It is generally very easy to inject hostile code and trick the JavaScript engine into running it. This is why we most often sandbox our JavaScript engines very carefully. So - I would basically do anything to avoid running node.js as root. And you probably should, too.

Bex
  • 2,929
  • 3
  • 26
  • 34
4

Eventually, it might be easier to get rid of your current installation based on your linked guide and try to follow the very simple steps offered by Adafruit.

https://learn.adafruit.com/node-embedded-development/installing-node-dot-js

Works very nicely and you'll get the latest node.js (v0.10.35) installed.

Regards, JoKi

JoKi
  • 56
  • 2