If you’re developing JavaScript applications on Ubuntu, knowing how to install Node.js on Ubuntu is essential. Node.js is a powerful runtime environment that enables server-side scripting, while npm, the Node Package Manager, allows you to manage your project’s dependencies easily. This guide will walk you through the steps to install Node.js and npm on Ubuntu, ensuring you have everything you need to start developing efficiently. Whether you’re using Ubuntu 20.04 or another version, this Node.js Ubuntu installation guide will help you set up quickly and easily.
Table of Content
- What is Node.js?
- What is NPM?
- Method 1: Using Official Repository for Node.js and npm Installation on Ubuntu
- Step 1: Open Terminal Window
- Step 2: Run the Command
- Step 3: Create a Symbolic Link
- Step 4: Check if node.js and npm is installed or not
- Method 2: Via using NodeSource Repository for Node.js and npm Installation on Ubuntu
- Step 1: Install Curl
- Step 2: Curl the Directory
- Method 3: By using NVM for Node.js and npm Installation on Ubuntu
- Step 1: Install NVM
- Step 2: Check if NVM is Installed
- Step 3: List Versions and Select
- Step 4: Switch to the Installed Version of Node.js
- Method 4: By using Snap Installer for Node.js and npm Installation on Ubuntu
- Step 1: Install Snap Using Terminal
- How to Install Node.js and npm on Ubuntu – FAQ’s
What is Node.js?
Node.js is a runtime environment that operates separately from the browser. It utilizes Chrome’s V8 JavaScript engine, enabling users to efficiently use the JavaScript programming language—which they may already be familiar with—to create backend applications, even at a beginner level. Node.js is versatile and can be used effectively by both front-end and back-end programmers.
What is NPM?
NPM, or Node Package Manager, is more than just a package manager and software registry system. It allows developers to locate, create, and manage essential code packages. Currently, NPM hosts over 800,000 packages for various uses, including front-end development, robotics, and Android applications, facilitating smooth interfaces. Initially developed as a package manager application for Node.js, it was aptly named NPM.
Methods For Installing Node &NPM On Ubuntu
Method 1: Using Official Repository for Node.js and npm Installation on Ubuntu
The node.js and npm are available in the official repository of Ubuntu, so using the official repository becomes the easiest method to Install Node.js and npm on Ubuntu, for this you will have to follow the below steps:
Step 1: Open Terminal Window
First, go to the start menu of the Ubuntu system and open the terminal, you can also use the shortcut key (CTRL+ALT+T) to open the terminal.
Step 2: Run the Command
Now you simply need to run the following command that will Install Node.js and npm on Ubuntu using the apt:
sudo apt install nodejs npm
This will give you the following output and Install Node.js and npm on Ubuntu for you:
sudo apt install nodejs npm.
Step 3: Create a Symbolic Link
Now you will have to create a symbolic link, the reason for this is that node js uses binary path /usr/bin/node but our installed path is /user/bin/nodejs so we will get an error as “No path or directory found” if we don’t create a symbolic link.
To create the symbolic link, run the following command:
ln -s /usr/bin/nodejs /usr/bin/node
This will give the following output if the link is already created by the repository, otherwise, it will create the link:
ln -s /usr/bin/nodejs /usr/bin/node.
Step 4: Check if node.js and npm is installed or not
This is the last step where we check whether the node.js and npm are installed or not, for this run the following command:
node --version
npm --version
If it shows output similar to the image below (version may differ) then npm and node.js are installed successfully:
node –versionnpm –version
Method 2: Via using NodeSource Repository for Node.js and npm Installation on Ubuntu
We can also directly Install Node.js and npm on Ubuntu using the official node source repository, for this, we follow the steps mentioned:
Step 1: Install Curl
First, we will have to install curl so that we can download third-party repositories easily, for this we will run the following command:
sudo apt update
sudo apt install -y curl
This will install the curl into to Ubuntu system, it will show “already installed” if your system has curl already otherwise it will install it for you.
sudo apt install -y curl.
Step 2: Curl the Directory
Now we will have to curl the source directory to install the node.js and npm, for this we run the following command:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
Note: Here we are using setup_18.x because it’s the latest version available for ubuntu, you can check if newer version is available and change the command accordingly.
sudo apt-get install -y nodejs.
This will install the node.js and npm on your system successfully.
Method 3: By using NVM for Node.js and npm Installation on Ubuntu
The NVM is also an easy to use and installer for the node and it offers the flexibility for us to easily switch between different versions of node, let’s understand step by step how to install node.js and npm using NVM:
Step 1: Install NVM
First, we will have to curl and install NVM, for this run the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
This will give us the following output:
curl nvm directory.
Step 2: Check if NVM is Installed
To check whether the NVM is installed or not we will run the following command:
command -v nvm
This will give us the following output:
command -v nvm.
Step 3: List Versions and Select
Now you simply need to list all the versions available and choose the one of your requirement, for this run the following command:
nvm list-remote
This will give us the following output:
nvm list-remote.
After this, you will have to enter the following command to install the version of your choice:
nvm install <version-name>
This will give us the following output:
nvm install
Step 4: Switch to the Installed Version of Node.js
Now simply run the following command and mention the version that you want to switch to:
nvm use <your-installed-version-number>
This will give the following output:
nvm use
Finally, you have successfully installed and switched to the version of your choice using NVM.
Method 4: By using Snap Installer for Node.js and npm Installation on Ubuntu
This is also another simple method where we use snap (third-party software) that acts as a play store for Ubuntu to provide installation of Ubuntu software, here are the steps:
Step 1: Install Snap Using Terminal
For this, we need to run the following command in our terminal:
sudo snap install node --classic
This will give the following output:
sudo snap install node –classic.
As you can see it installed the node 20.11.1 version for us.
Also Read
- Node.js Introduction
- NodeJS Tutorial
- Node JS NPM
Conclusion
Installing Node.js and npm on Ubuntu is a straightforward process that opens up a world of possibilities for JavaScript development. By following the steps outlined in this guide, you can easily set up npm on Ubuntu and start building your projects in no time. Whether you’re new to Ubuntu or an experienced user, this guide ensures that you have a smooth and hassle-free Node.js installation on Ubuntu. Get started today and leverage the power of Node.js and npm for your next project!
How to Install Node.js and npm on Ubuntu – FAQ’s
How do I install Node.js on Ubuntu using the terminal?
To install Node.js via terminal Ubuntu, you can use the package manager apt by running sudo apt update followed by sudo apt install nodejs. For npm, use sudo apt install npm.
Can I install the latest Node.js on Ubuntu?
Yes, you can install the latest version of Node.js by adding the NodeSource repository to your system and then using apt to install it. This guide provides detailed instructions on how to install the latest Node.js on Ubuntu.
What is the best way to set up npm on Ubuntu?
The best way to install npm on Ubuntu is by using the official package manager. After installing Node.js, npm typically gets installed automatically, but you can also install it separately using sudo apt install npm.
Is there a step-by-step guide to installing Node.js and npm on Ubuntu?
Yes, this guide offers a comprehensive step-by-step tutorial to install Node.js on Ubuntu and set up npm on Ubuntu, making it easy for both beginners and experienced users to follow.
Next Article
How to Install Node.js on a Webserver ?