Lately I find lot of interesting projects that run over #NodeJS, and TBH I have no too much idea. So then what is better than installing it at home to play around? In this article I go through the (really easy) installation process of Node JS 20.

Overview

  1. Requirements & assumptions

  2. Install NodeJS

  3. Wrapping up

1. Requirements & assumptions

  • A Raspberry Pi up and running, following my previous article Spawning a Raspberry Pi 4 with Raspberry Pi OS. It is also up to date by following the recent article Upgrade Raspberry Pi OS from 11 Bullseye to 12 Bookworm.

  • What is the goal? This will shape your installation, for example your may be installing NodeJS so that you can serve an app like [Postmarks]((https://github.com/ckolderup/postmarks) that at this point uses version 16. Please consider what are the requisites, not all apps are 100% compatible with versions backwards. Here I'll focus on installing the latest version of NodeJS

2. Install NodeJS

ℹ️ The current version of Node.js when writing this article was 20.7.0

2.1. Preparing to get the repositories

Before adding the repositories from where I will get the packages, I need to install some Debian packages so it can talk with the server properly.

This step may not be necesserary if we didi it already with a previous installation, for example.

  1. Update the package list and upgrade the existing packages, as usual.

    sudo apt update
    sudo apt upgrade
  2. Install the debian packages that will allow us to interact with the external packages repositories

    sudo apt install -y ca-certificates curl gnupg

Now we're ready to add external repositories and interact with them as usual.

2.2. Set up the repositories in the APT package manager

  1. Download the GPG key

    curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg
  2. Define which version of NodeJS do we want to download. This is done by definin a environment variable. If you prefer another version, just edit the value.

    NODE_MAJOR=20
  3. Add the NodeJS repository

    echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
  4. Update the package list

    sudo apt update

2.3 Install NodeJS

And now we can install NodeJS as any other package in the system

sudo apt install nodejs

2.4 Test the installation

Let's just see which version do we have installed

nodejs -v

This should output (in my case):

v20.7.0

3. Wrapping up

As seen, installing NodeJS is very straight forward and comes with no complication. Hopefully this enables you to play around with any great project!

Previous Post Next Post