Node.js is an open-source, cross-platform JavaScript runtime environment used for executing JavaScript code outside of a web browser.It's lightweight, and beginner friendly and used by many big companies like Netflix and Uber
There are different ways to install Node.js on a Linux-based system. However, in this tutorial, we will focus on two comonly used methods: using the official package manager and using the Node.js version manager (nvm).
Method 1: Using the Official Package Manager
The easiest way to install Node.js on a Linux system is by using the official package manager of your distribution.
-
Ubuntu/Debian
Open the terminal and update the package index:
sudo apt-get update
-
Install NodeJS
sudo apt-get install nodejs
-
Verify the installation
To check if Node.js is installed correctly, run the following command:
node -v
This should output the version number of Node.js installed on your system.
-
Install npm:
npm is a package manager for Node.js. To install it, run the following command:
sudo apt-get install npm
-
Verify the installation
To check if npm is installed correctly, run the following command:
npm -v
This should output the version number of npm installed on your system.
-
Update npm:
It is always recommended to update npm to its latest version. Run the following command to update npm:
sudo npm install -g npm
Method 2: Using the Official Package Manager
The Node Version Manager (nvm) is a tool that allows you to easily switch between different versions of Node.js on your system.
-
Install nvm
Open the terminal and run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
This will download and install nvm on your system.
Troubleshooting on Linux
On Linux, after running the install script, if you get
nvm: command not found
or see no feedback from your terminal after you typecommand -v nvm
, simply close your current terminal, open a new terminal, and try verifying again.
Alternatively, you can run the following commands for the different shells on the command line:bash:
source ~/.bashrc
zsh:
source ~/.zshrc
ksh:
. ~/.profile
These should pick up the
nvm
command. -
Verify the installation
To check if nvm is installed correctly, run the following command:
nvm --version
This should output the version number of nvm installed on your system.
-
Install Node.js:
Once you have nvm installed, you can use it to install any version of Node.js that you want. For example, to install the latest stable version of Node.js, run the following command:
nvm install --lts
-
Verify the installation
To check if Node.js is installed correctly, run the following command:
node -v
This should output the version number of Node.js installed on your system.
Conclusion
In this tutorial, we have shown you two ways to install Node.js on a Linux system: using the official package manager and using the Node Version Manager (nvm). Choose the method that best suits your needs and get started with building amazing web applications with Node.js!
Top comments (3)
Another alternative (my favorite) is asdf
Is it written by AI
using quillbot to improve the sentences