Welcome to the world of Node.js, a powerful, open-source, and cross-platform JavaScript runtime environment that executes JavaScript code outside the confines of a web browser. Developed by Ryan Dahl in 2009, Node.js is built on Chrome’s V8 JavaScript engine, enabling developers to create server-side applications using JavaScript. Over the years, Node.js has gained immense popularity among developers thanks to its flexibility, performance, and ease of use. In this introduction, we’ll delve into the unique features that set Node.js apart, and by the end, you’ll have a solid understanding of why it’s a must-have in your development toolkit.
Here’s a detailed list of what makes Node.js stand out:
- Asynchronous and Event-Driven: Node.js is built around an asynchronous, event-driven architecture, which means it can handle multiple requests simultaneously without waiting for any of them to complete. This results in improved performance and scalability.
- Non-Blocking I/O: Node.js utilizes a non-blocking input/output (I/O) model, which allows it to efficiently manage multiple connections and process data without being bogged down by individual requests.
- Modularity: Node.js supports a modular approach, making it easy for developers to create, manage, and reuse code. It uses the CommonJS module system and has a vast ecosystem of third-party modules available through the Node Package Manager (npm).
- Cross-Platform Compatibility: Node.js is compatible with various operating systems, including macOS, Linux, and Windows, making it a versatile choice for diverse development environments.
- Extensive Ecosystem: Node.js has a rich ecosystem with a large community that continually contributes to its growth. This includes countless libraries, frameworks, and tools that simplify and expedite the development process.
Now that you have a solid understanding of Node.js and its unique features, it’s time to get started with the installation process. The guide will demonstrate how to install Node.js on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster using the NodeSource third-party repository, which is the best and safest method to ensure you are working with the latest up-to-date Node.js of the particular supported version you want to work with, either the latest stable or LTS.
Table of Contents
Section 1: Install Node.js from Debian Repository
In this section, we’ll go over how to install Node.js directly from the Debian repository. This method is simple and straightforward, but it might not provide the latest version of Node.js.
Step 1: Update Package List
Before installing Node.js, updating the package list is important to ensure you get the most recent version in the repository. Run the following command:
sudo apt update
This command will update the package list and provide information about any available updates for your system.
Step 2: Install Node.js
Now that your package list is updated, you can install Node.js using the following command:
sudo apt install nodejs
This command will install Node.js along with its required dependencies. Once the installation is complete, you can check the installed version by running:
nodejs -v
This will display the installed version of Node.js on your system.
Section 2: Install Node.js using NodeSource PPA
If you want to install a more recent version of Node.js, you can use the NodeSource PPA. This method allows you to choose a specific version of Node.js and ensures you’re getting the latest release.
Step 1: Add NodeSource PPA
To add the NodeSource PPA to your system, run the following command:
curl -fsSL https://deb.nodesource.com/setup_<version>.x | sudo -E bash -
Replace <version>
with the desired major version of Node.js. This command will download and run a script that adds the NodeSource PPA to your system and updates your package list. Common Examples:
Import the Node.js current stable repository:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
Import the Node.js long-term support repository:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -
Step 2: Install Node.js
With the NodeSource PPA added, you can now install Node.js using the following command:
sudo apt install nodejs
This command will install the specified version of Node.js along with its required dependencies. After the installation is complete, you can check the installed version by running:
node -v
This will display the installed version of Node.js on your system.
Section 3: Install Node.js using NVM
Another way to install Node.js is by using the Node Version Manager (NVM). This method allows you to manage multiple Node.js versions on your system, making switching between versions for different projects easier.
Step 1: Install NVM
To install NVM, run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
This command downloads and runs the NVM installation script. Once the installation is complete, you need to restart your terminal or run the following command to load NVM:
source ~/.bashrc
Step 2: Install Node.js using NVM
In this step, we’ll install Node.js using the Node Version Manager (NVM). NVM allows you to manage multiple Node.js versions on your system, making switching between versions for different projects convenient.
2.1: List available Node.js versions
Before installing a specific version of Node.js, you can check the available versions by running:
nvm ls-remote
This command will display a list of all available Node.js versions. It helps you identify the version you want to install, such as the latest LTS release or a specific version number.
Example NVM ls remote output on Debian terminal:
2.2: Install a Node.js version
With NVM installed, you can now install the desired version of Node.js by running:
nvm install <version>
Replace <version>
with the specific version you want to install. For example, if you want to install Node.js version 19.9.0, you would run:
nvm install 19.9.0
This command will download and install the specified version of Node.js.
Example output if successful:
2.3: Verify Node.js installation
To check the installed version of Node.js, run:
node -v
This will display the installed version of Node.js on your system.
2.4: Switch between installed Node.js versions
NVM allows you to switch between different Node.js versions easily. To switch between installed Node.js versions, use the following command:
nvm use <version>
Replace <version>
with the version you want to switch to. For example, if you want to switch to Node.js version 18.16.0, you would run:
nvm use 18.16.0
This command will set the specified version as the active Node.js version for your current session. To make a specific Node.js version the default for new terminal sessions, use the command:
nvm alias default <version>
Replace <version>
with the desired version number. For example, to set Node.js version 18.16.0 as the default, you would run:
nvm alias default 18.16.0
Example:
Now you have successfully installed and learned how to manage Node.js versions using NVM.
Section 4: How to Remove Node.js from Debian
Step 1: Uninstall Node.js installed from Debian Repository or PPA
If you installed Node.js from the Debian repository or a PPA, you can uninstall it using the apt
program. First, let’s explain the command:
sudo apt remove nodejs
This command will remove Node.js along with its associated configuration files. It will prompt you to confirm the removal, and after confirmation, it will proceed with the uninstallation.
Step 2: Uninstall Node.js installed using NVM
If you installed Node.js using the Node Version Manager (NVM), you can uninstall it by following these steps:
2.1: Check the current Node.js version
First, check the current version of Node.js installed by running the command:
nvm current
This command will display the active Node.js version on your system.
2.2: Deactivate NVM
Before uninstalling the current version of Node.js, you need to deactivate NVM by running:
nvm deactivate
This command will unload the active Node.js version from your current session.
2.3: Uninstall Node.js version using NVM
Now, run the following command to uninstall a specific version of Node.js installed using NVM:
nvm uninstall <version>
Replace <version>
with the version number you want to uninstall. For example, if you want to uninstall Node.js version 19.9.0, you would run:
nvm uninstall 19.9.0
This command will remove the specified Node.js version from your system.
Conclusion: Installing Node.js on Debian Linux
In summary, there are multiple ways to install Node.js on a Debian Linux system. Depending on your requirements, you can choose to install Node.js from the Debian repository, using the NodeSource PPA, or with the Node Version Manager (NVM). Each method has its advantages, with NVM offering the most flexibility for managing multiple Node.js versions on your system. As you progress in your development journey, you’ll be able to choose the installation method that best suits your needs, ensuring a seamless and efficient workflow.
Additional Resources and Links
Below is a list of official resources and links to help you learn more about Node.js and its related technologies. These resources include official documentation, forums, and wikis, which provide valuable information for developers at all skill levels.
- Node.js Official Website: The official website for Node.js, where you can find the latest news, updates, and information about the project. Visit https://nodejs.org for more details.
- Node.js Documentation: The official documentation for Node.js, which includes guides, API references, and other resources to help you learn and understand the platform better. Check out the documentation at https://nodejs.org/en/docs/.
- NVM GitHub Repository: The official GitHub repository for the Node Version Manager (NVM) project, where you can find the latest releases, source code, and issue tracking. Visit the NVM GitHub repository at https://github.com/nvm-sh/nvm.
- Node.js GitHub Repository: The official GitHub repository for the Node.js project, which contains the source code, issue tracking, and collaboration tools for the development of Node.js. You can find the Node.js GitHub repository at https://github.com/nodejs/node.