Install Node.js and npm
Connect to Raspberry Pi via SSH and add NodeSource repository that maintains Node.js 16 binary distributions.
curl -sSL https://deb.nodesource.com/setup_16.x | sudo bash -
Run command to install Node.js:
sudo apt install -y nodejs
Note that, we don't need to install npm separately, it comes bundled with Node.js. After the installation is complete, check Node.js and npm versions:
node --version npm --version
Navigate to your home directory and create a new
cd ~ nano main.js
When a file is opened, add the following code:
Now use the
node command to test a program:
Uninstall Node.js and npm
We can remove any package with a name that starts with
nodejs and anything related to it by running the following command:
sudo apt purge -y nodejs.*
We can also remove NodeSource repository and signing key:
sudo rm -rf /etc/apt/sources.list.d/nodesource.list sudo rm -rf /usr/share/keyrings/nodesource.gpg
Install older versions
Node.js 14 is older LTS version that is still supported. It can be installed by adding the following NodeSource repository:
curl -sSL https://deb.nodesource.com/setup_14.x | sudo bash -
The 5 Comments Found
thank you so much for this great tutorial, it was very helpful.
Very interesting blog post.Quite informative and very helpful. I’m a regular reader of your blog Thank you for providing such a nice piece of article. I’m glad to leave a comment. Expect more articles in the future.
I’m struggling to get Node v16 installed on ARMv6. Anyone able to get past this with the first command?
## Installing the NodeSource Node.js 16.x repo...
## You appear to be running on ARMv6 hardware. Unfortunately this is not currently supported by the NodeSource Linux distributions. Please use the 'linux-armv6l' binary tarballs available directly from nodejs.org for Node.js 4 and later.
NodeSource repository doesn't provide Node.js for ARMv6 architecture. You can try to find unofficial builds and install manually.
Leave a CommentCancel reply