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.
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
ℹ️ The current version of Node.js when writing this article was 20.7.0
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.
Update the package list and upgrade the existing packages, as usual.
sudo apt update
sudo apt upgrade
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.
Download the GPG key
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg
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.
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
Update the package list
sudo apt update
And now we can install NodeJS as any other package in the system
sudo apt install nodejs
Let's just see which version do we have installed
This should output (in my case):
As seen, installing NodeJS is very straight forward and comes with no complication. Hopefully this enables you to play around with any great project!