Installing Node.js on Raspberry Pi OS
- Open a Terminal session from the taskbar.
- Update your package list first:
sudo apt update && sudo apt upgrade - Install Node.js and npm via NodeSource’s setup script for the LTS release (recommended over the version in Raspberry Pi OS’s default repos, which is often quite old):
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt install -y nodejs
- Confirm the install:
node -vandnpm -v
apt list nodejs before adding the NodeSource repository, since sometimes the built-in package is now current enough that you don’t need the extra step at all.
Which Pi model does this work on?
The NodeSource install script above works on any current Raspberry Pi OS release across the 32-bit (armhf) and 64-bit (arm64) builds, so it’s the same process whether you’re on a Pi 4, Pi 5, or a Zero 2 W. On the original Pi Zero/Pi 1 (armv6), NodeSource dropped official armv6 builds some time ago — on those older boards, use an armv6-compatible Node build via a version manager likenvm, or check the Pi OS repo package first since it’s more likely to still carry an armv6-compatible build.
Managing multiple Node versions
If you need to switch between Node versions for different projects (rather than always running whatever NodeSource’slts.x script installs), nvm (Node Version Manager) works on Raspberry Pi OS the same as on any other Linux distribution and avoids the need to reinstall system-wide each time you need a different version:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash nvm install --ltsCheck the nvm project page for the current release tag if that version number has moved on since this was written.
Resources
Discover more from TechyGeeksHome
Subscribe to get the latest posts sent to your email.