Node.js has become a critical component for building fast, scalable web applications. If you’re using Debian 12 and want to install the latest version of Node.js, such as v20.x, here’s a quick guide to get you started.
Step 1,Update Your System
Before installing Node.js, it’s always a good idea to ensure your system is up-to-date. You can do this by running:
1 |
sudo apt update && sudo apt upgrade -y |
This will ensure you have the latest security patches and updates.
Step 2, Install the Required Dependencies
To install Node.js, we need to install a few prerequisite packages. These will allow Debian to manage new repositories and downloads:
1 |
sudo apt install curl software-properties-common -y |
Step 3, Add the NodeSource Repository
Node.js v20.x is not available in the default Debian repositories, so we’ll need to use NodeSource. Run the following command to add the NodeSource repository for Node.js v20.x:
1 |
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - |
This command downloads and sets up the necessary repository for Node.js.
Step 4, Install Node.js
Now that the NodeSource repository has been added, you can install Node.js v20.x by running:
1 |
sudo apt install nodejs -y |
This command will install both Node.js and npm (Node.js package manager).
Step 5, Verify Installation
Once installed, you can verify the installation of Node.js and npm by checking their versions:
1 2 |
node -v npm -v |
You should see something like:
1 |
v20.x.x |
and for npm:
1 |
x.x.x |
This means Node.js and npm have been successfully installed on your Debian 12 system.
Step 6, Optional – Install Build Tools
For some Node.js packages, you may need to install additional build tools. You can install them by running:
1 |
sudo apt install build-essential -y |
These tools will allow you to compile native Node.js modules.
Step 7, Managing Node.js Versions (Optional)
If you ever want to manage multiple versions of Node.js, you can use nvm
(Node Version Manager). However, if you installed Node.js using NodeSource, you are already using the latest stable version.
To install nvm
, run the following:
1 |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash |
You can now install and switch between different Node.js versions easily with nvm
.
By following these steps, you should have Node.js v20.x up and running on your Debian 12 system. Node.js brings a powerful environment for building scalable network applications, and now you’re all set to start developing!
Happy coding!