Node.js Setup: Linux/Embedded Systems

x86/x64 Linux Desktop

Head over to https://nodejs.org/en/download/ to get the download url to NodeJS. For this demonstration, NodeJS (v7.2.0) will be installed on Ubuntu 16.04.1.

10521052

Next, open up Terminal and use wget to download the Linux binary.

wget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-x64.tar.xz
746746

Now use tar to unpack the file.

 tar -xvf node-v7.2.0-linux-x64.tar.xz
746746

Install NodeJS into /usr/local/.

cd node-v7.2.0-linux-x64
sudo cp -R * /usr/local/
746746

You can check that NodeJS and NPM are installed correctly by confirming their version numbers from Terminal by running

node -v
npm -v
746746

ARM/Raspbery Pi

Depending on which version of Raspberry PI you are using (1,2,3, Zero, etc) you will need to download the appropriate pre-compiled binary (ArmV7, ArmV8).

These instructions will show the process for a Raspberry Pi 3 (Running 2016-05-27-raspbian-jessie-lite).

Download and unpack NodeJS (ArmV7).

wget https://nodejs.org/dist/v7.2.0/node-v7.2.0-linux-armv7l.tar.xz
tar -xvf node-v7.2.0-linux-armv7l.tar.xz
589589 617617

Install NodeJS into /usr/local/.

cd node-v7.2.0-linux-armv7l
sudo cp -R * /usr/local/

At this point you can test Node to confirm that you have installed the correct version.

617617

🚧

Incorrect NodeJS Version

If node -v reports something similar to -bash: /usr/local/bin/node: cannot execute binary file: Exec format error or does not respond, you may have installed a version of NodeJS not compatible with your operating system architecture. You can simple repeat the install process with the correct version as it will overwrite the previously installed files.

Clean up the temporary files.

cd ~
rm -rf node-v7.2.0-linux-armv7l
rm node-v7.2.0-linux-armv7l.tar.xz

NodeJS and NPM are now installed!

Installing Node modules globally (Linux Desktop/ Embedded)

You can install some npm packages globally, such as the droplit.io CLI, to run them from any directory.

npm install droplit-cli -g
746746

However, you may encounter an error like this when installing npm packages globally.

746746

There are a few ways to solve this issue according to docs.npmjs.com. We prefer Option 2 as it does not require changing directory ownership, which may be a security risk.

First, change the install location of global packages.

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Create/edit .bashrc to add the new directory to your PATH.

echo "export PATH=~/.npm-global/bin:\$PATH" >> ~/.bashrc

Make sure you are the owner of the ~/.npm-global/ directory, or assert your ownership using the following

chown <username>:users ~/.npm-global

Restart your terminal and you should be able to install and use global packages.

📘

You can use .bash_profile instead of .bashrc if you wish.

The .bash_profile is only executed for a login-shell, whereas .bashrc is executed for every new shell instance

MIPS/OpenWRT

If you wish to run NodeJS on an OpenWRT device and node is not already provided for your distribution or node is provided and you require a new version, you should be familiar with OpenWrt's build system.

This article explains how to cross compile NodeJS for OpenWRT.

Once you have the NodeJS Binary file, transfer it to your OpenWRT device. You may need to mark it as executable.

chmod node 755

Depending on CPU speeds, we recommend downloading npm packages on a different computer and transfer them to your device. If any of your packages require compilation, you will want to compile them with your toolchain.

🚧

FPU emulation

In our testing, we found that the OpenWRT kernel required FPU emulation be enabled for NodeJS to run. Without FPU Emulation, we tested many different versions of NodeJS (0.10 - 6.0.0), and each would result in a floating point exception or not respond. When compiling your OS make sure that you have this feature enabled.