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
  • 25
  • 34
  • 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: http://raspberrypi.stackexchange.com/questions/26967/npm-install-failes-von-raspbian?noredirect=1#comment33657_26967 – Boas Enkler Jan 20 '15 at 08:54
  • Did you try running sudo /opt/node-v0.10.28-linux-arm-pi/bin/node --version? – Bex Jan 20 '15 at 08:56
  • i'm not sure, I'll try it this afternoon – Boas Enkler Jan 20 '15 at 09: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: http://unix.stackexchange.com/questions/83191/how-to-make-sudo-preserve-path – 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
  • Ok. Have a look on my secons paragraph. Now, at least, you can run the command as stated in your other question. – Bex Jan 21 '15 at 08:14
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