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

  • 2
    As explained several times, that IS NOT the $PATH used by sudo. – goldilocks Jan 20 '15 at 20:19
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

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.

  • Your right. Normally i don't want to run this with sudo rights. But nevertheless i would like to understand why this doesn't work. And also there was a library which claimed to need sudo permissions. I also descriped the problem why i want to testrun this with sudo here: raspberrypi.stackexchange.com/questions/26967/… – Boas Enkler Jan 20 '15 at 8:54
  • Did you try running sudo /opt/node-v0.10.28-linux-arm-pi/bin/node --version? – Bex Jan 20 '15 at 8:56
  • i'm not sure, I'll try it this afternoon – Boas Enkler Jan 20 '15 at 9:34
  • @BoasEnkler Which part of this answer do you not understand? Bex does describe exactly why this doesn't work (note "root profile" == /root/.profile). If you would like to read another version of the same thing, keeping in mind Raspbian is Debian: unix.stackexchange.com/questions/83191/… – goldilocks Jan 20 '15 at 11:50
  • Well in both cases the path is printed out ( I updated the question) – Boas Enkler Jan 20 '15 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.