“Node.js” is a powerful and open-source runtime environment for Javascript that permits you to employ the Javascript as both, the front-end and back-end. It is well-known for its quickness, extensibility, and a large ecosystem of different libraries. It is currently deployed in web applications and API’s.
It is not pre-installed on Debian 12 and to install it, you must follow certain steps. This guide enables you to install it on Debian 12.
How to Install “Node.js” on Debian 12
You can install the “Node.js” that comes bundled with “NVM” via the following methods:
- Using the Default Repositories.
- Using the NodeSource PPA Repository.
- Using the NVM.
Method 1: Using the Default Repositories
“Node.js” is officially available in the default repositories and you can install it via the traditional “apt” command, as seen below:
sudo apt install nodejs npm -y
To verify the installation of “Node.js” on Debian 12, run the below command:
nodejs --version
You can verify the installation of “npm” as well, via the following command:
npm --version
Bonus Tip: How to Install the “Node.js” LTS Version on Debian 12
The “LTS” version of “Node.js” is focused more towards the stability of any application that is run. The “LTS” stands for “Long Term Support” and is maintained using the latest security patches. To install the “Node.js” LTS version, run:
nvm install --lts
Bonus Tip: How to Remove “Node.js” Installed From the Default Repositories in Debian 12
If you have installed the “Node.js” using the default repositories in Debian 12, run the following command to remove it:
sudo apt remove nodejs npm -y
Method 2: Using the NodeSource PPA Repository
You can install the “Node.js” using the “NodeSource PPA Repository” as well. Utilizing this approach, you can download/install the newest version from the specified version. Below is a command to install the newest version from the “20” series of the “Node.js” on Debian 12:
sudo curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt install nodejs -y
To verify the “Node.js” and “npm” installation, execute the below commands:
node -v
npm -v
Additionally, you can always install the “Node.js” newest version (21.x as of this writing) on Debian 12 via the following command:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - &&
sudo apt install -y nodejs
To check the current version of “Node.js” and “npm”, execute the following command:
node -v
npm -v
Bonus Tip: How to Uninstall/Remove the “Node.js” Installed Via the NodeSource PPA Repository
To uninstall the “Node.js” and remove its repository (NodeSource PPA), execute the below-mentioned command:
sudo apt purge nodejs && sudo rm -r /etc/apt/sources.list.d/nodesource.list
Method 3: Using the “NVM”
If you want to install “NVM”, “Node.js” is automatically installed with it. To trigger the installation of the newest “NVM” and “Node.js” versions, follow these steps:
Step 1: Download the “NVM” Installation Script
The installation script of the “NVM” is hosted on one of GitHub’s domains. To download it, run:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Step 2: List the Available “NVM” Versions
You can specify which version of “NVM” you want to install from a list. To view the list of the “NVM” versions, use the below mentioned command:
nvm ls-remote
Step 3: Install “Node.js” Via “NVM”
Now, for installing the “Node.js” via the “NVM” run the below command and replace the version (v21.6.1 in this case):
nvm install v21.6.1
Step 4: Switch/Set the Default “NVM” Version (Optional)
To use or switch with a specified version of “Node.js” in the current session based on your preferences (21.6.1 in this case) run the following command:
nvm use v21.6.1
To set the above as the “Node.js” default version, execute the below command:
nvm alias default v21.6.1
Bonus Tip: How to Uninstall/Remove the “Node.js” Installed Using the “NVM”
Run the below command to uninstall the “Node.js” version installed using the “NVM”; however, you must know the version you have installed:
nvm uninstall v21.6.1
Final Words
To install the newest public version of “Node.js” on Debian 12, use the default repositories and run the command “sudo apt install nodejs npm”. Additionally, you can install the “Node.js” on Debian 12 via the “NodeSource PPA Repository”.
The recommended method to install the “Node.js” is through the “NVM” as it lets you select the version that suits what you require. This guide has shed light on the methods for installing the “Node.js on Debian 12”.
Frequently Asked Questions
How to install Node.js on Debian 12 using NVM?
You can install Node.js on Debian 12 using NVM by running the command 'nvm install node'. This method allows you to manage multiple Node.js versions easily.
What is the LTS version of Node.js and how to install it on Debian 12?
The LTS version of Node.js stands for Long Term Support and is more focused on stability. To install the LTS version on Debian 12, you can use the command 'nvm install --lts'.
How to remove Node.js installed from the default repositories in Debian 12?
To remove Node.js installed from the default repositories in Debian 12, you can run the command 'sudo apt remove nodejs npm -y'. This will uninstall Node.js and npm from your system.
Can Node.js be installed on Debian 12 using the NodeSource PPA Repository?
Yes, you can install Node.js on Debian 12 using the NodeSource PPA Repository. This method allows you to download and install the latest version of Node.js from the specified repository.
What are the benefits of using NVM to install Node.js on Debian 12?
Using NVM to install Node.js on Debian 12 allows you to easily manage multiple Node.js versions on your system. It provides flexibility and convenience for developers.
How to verify the installation of Node.js on Debian 12?
To verify the installation of Node.js on Debian 12, you can run the command 'nodejs --version'. This will display the installed Node.js version on your system.
Why is Node.js popular for web applications and APIs?
Node.js is popular for web applications and APIs due to its quickness, extensibility, and large ecosystem of libraries. It allows developers to use JavaScript for both front-end and back-end development.
What is the difference between Node.js and npm?
Node.js is a runtime environment for executing JavaScript code, while npm is a package manager for Node.js that helps in installing, updating, and managing dependencies in a project.