How to Install Node.js and npm on Debian 11
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Install Node.js on Debian
You can install Node.js using NodeSource, NVM, and Debian repository. So, follow any one of the methods you think is easier to install Node.js.
You may need to install the curl package before proceeding further.
sudo apt update && sudo apt install -y curl
Install Node.js using NodeSource
At the time of writing this article, the below versions of Node.js is available for user. You can visit the official page to find the supported Node.js versions.
- v14.x (Active LTS)
- v12.x (Maintenance LTS)
- v16.x (Latest Version)
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt install -y nodejs
curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt install -y nodejs
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs
Install Node.js using NVM
nvm is a version manager for Node.js, and it helps us install Node.js per user and invokes it per shell. Also, it allows you to install and use multiple versions of node.js in parallel.
nvm by running the below command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Once the nvm is installed, exit the current session and log in back to use the
Use the below command to verify the
Now, you can use the
nvm command to install the latest stable version of Node.js, the latest LTS version, a specific version of Node.js.
# Latest Stable Version nvm install node # Latest LTS Version nvm install --lts # Specific Version nvm install 12.22.5
nvm ls-remoteto list the available Node.js version to install,
nvm use node/--lts/<version>to change to another Node.js version,
nvm alias default <version>to set the default Node.js version.
Install Node.js using Debian Repository
Node.js is also available in the Debian repository, and you can install it along with npm (Node Package Manager)using the below command.
Node.js v12.x (LTS) and npm v7.5.x are available in the Debian OS repository when writing this article.
sudo apt install -y nodejs npm
Check Node.js Installation
Check the Node.js version using the following command.
Output: (NodeJS v14.x)
Check the npm version.
Install Build Tools
You will need to install development tools to compile and install native addons from npm.
sudo apt install -y build-essential