Installing Node.js on Raspberry Pi 3 (Raspbian) Using NVM: A Detailed Guide
In this article, we will cover the process of installing Node.js on a Raspberry Pi 3 running Raspbian using NVM (Node Version Manager). This method is recommended over the direct installation of Node.js, as it allows for easy management of multiple Node.js versions on a single system.
Background
Previously, Node.js was installed directly on the Raspberry Pi 3 using the package manager. However, this method has been replaced with the use of NVM, which provides a more streamlined and flexible approach to managing Node.js versions.
Installing NVM
To begin, we will need to install NVM on our Raspberry Pi 3. This can be done by running the following commands:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
These commands will download and install NVM, and then add it to our system's profile. This will allow us to use NVM to manage Node.js versions on our system.
Installing Node.js
Now that we have NVM installed, we can use it to install Node.js. We can list the available versions of Node.js using the following command:
nvm ls-remote
Once we have selected the version of Node.js that we want to install, we can use the following command:
nvm install
For example, to install Node.js version 14.17.3, we would run:
nvm install 14.17.3
This will install Node.js and its dependencies on our system.
Setting the Default Node.js Version
Once we have installed Node.js, we can set it as the default version using the following command:
nvm alias default
For example, to set Node.js version 14.17.3 as the default, we would run:
nvm alias default 14.17.3
Verifying the Installation
We can verify that Node.js has been installed correctly by running the following command:
node -v
This should display the version of Node.js that we have installed.
In this article, we have covered the process of installing Node.js on a Raspberry Pi 3 running Raspbian using NVM. This method provides a more flexible and streamlined approach to managing Node.js versions on our system.
References
- Node Version Manager (NVM) documentation: https://github.com/nvm-sh/nvm
- Node.js documentation: https://nodejs.org/en/docs/
- Raspberry Pi documentation: https://www.raspberrypi.org/documentation/