Node.js is a common and powerful server environment for JavaScript, and is handy to be able to work with for just about any Raspberry Pi project — it’s also one of those libraries that often requires multiple Google searches to remember how to get it installed, so I’ve consolidated my steps down to a single page. Hopefully, you’ll only need one search next time! (and hopefully I’ll remember that I wrote this, so I won’t need any!)
- Install Node.js – you might have a node installation on your Pi already, but chances are it’s not the one you want. Instead, grab a fresh one:
curl -sL https://deb.nodesource.com/setup_9.x | sudo bash -
sudo apt-get install nodejs
- Verify this worked with
node -v
andnpm -v
(as of this writing, I get 9.4.0 and 5.6.0, respectively)
- Install the Yarn dependency manager, which we’ll use to run our app:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
- Run
yarn -v
to verify (Version 1.3.2 as of today)
- Install a few handy packages using apt-get – you might not need these, but I find them necessary for many of my projects
sudo apt-get update
-
sudo apt-get install build-essential libavahi-compat-libdnssd-dev git
That’s it – easy, when you have everything in place!