How to Install Node.js and npm on Ubuntu?
Last Updated :
22 Aug, 2024
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.
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 --versionMethod 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
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.
Similar Reads
How to Install Node.js and npm on Ubuntu?
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 w
7 min read
How to Install NVM on Ubuntu 22.04
Whether you're building a web app, working with a Node.js-based framework, or simply learning Node.js, NVM simplifies the process of managing your Node.js environments on Ubuntu. Basically, NVM (Node Version Manager) is a handy tool for managing multiple versions of Node.js on your system. With NVM,
5 min read
How to Install Node.js on a Webserver ?
Node.js is a powerful, lightweight, and efficient runtime for executing JavaScript code on the server side. It is particularly well-suited for building scalable network applications. Installing Node.js on a web server enables developers to run server-side JavaScript, host web applications, and serve
2 min read
How to Install Node.js on Windows
Installing Node.js on Windows is a straightforward process, but it's essential to follow the right steps to ensure smooth setup and proper functioning of Node Package Manager (NPM), which is crucial for managing dependencies and packages. This guide will walk you through the official site, NVM, Wind
6 min read
How To YUM Install Node.JS On Amazon Linux ?
yum stands for Yellowdog Updater Modified is a package manager utility for Red Hat-compatible Linux operating systems. just like 'apt' used for Ubuntu distribution yum is used to install, update, and remove software packages. yum simplifies the process of installing software packages and ensures tha
3 min read
How to Install Node & Run npm in VS Code?
Node is an open-source, server-side JavaScript runtime environment built on the V8 engine. It allows developers to execute JavaScript code outside of a web browser, enabling the development of scalable and efficient network applications. Known for its event-driven architecture, NodeJS is widely used
2 min read
How to Download and Install Node.js and NPM
The Node.js can be installed in multiple ways on a computer. The approach depends on the existing development environment in the system. In this guide, we’ll walk you through the process of downloading and installing Node.js and NPM on your system. Whether you're on Windows, macOS, or Linux, this gu
6 min read
How To Install A Local Module Using NPM?
To install a local module using npm, it's important to understand how npm (Node Package Manager) works with local packages. npm allows you to manage and install various JavaScript packages and modules, whether they’re from a remote repository or locally on your system. Installing a local module is p
3 min read
How to install modules without npm in node.js ?
We can install modules required for a particular project in node.js without npm, the recommended node package manager using yarn. Yarn is a wonderful package manager. Like npm, if you have a project folder with package.json containing all the required dependencies mentioned for the project, you can
3 min read
How to Install and Set Up math.js?
Math.js is the JavaScript library that provides a wide range of mathematical functions and capabilities, making it an essential tool for developers working on complex mathematical computations and data analysis. It supports a variety of data types, including numbers, big numbers, complex numbers, an
2 min read
How to Install and Use NVM on Windows?
Node Version Manager, commonly known as NVM, is a robust tool designed for managing and installing multiple versions of Node.js. It provides the flexibility to switch between different Node.js versions seamlessly, catering to the specific requirements of various projects. Additionally, it facilitate
2 min read
How to Install Node.js on Linux
Installing Node.js on a Linux-based operating system can vary slightly depending on your distribution. This guide will walk you through various methods to install Node.js and npm (Node Package Manager) on Linux, whether using Ubuntu, Debian, or other distributions. PrerequisitesA Linux System: such
5 min read
How to Install NodeJS on MacOS
Node.js is a popular JavaScript runtime used for building server-side applications. It’s cross-platform and works seamlessly on macOS, Windows, and Linux systems. In this article, we'll guide you through the process of installing Node.js on your macOS system. What is Node.jsNode.js is an open-source
7 min read
How to install the previous version of Node and npm?
Installing a specific version of Node.js and npm can be essential for compatibility reasons or to work with legacy projects. In this guide, we’ll go through the steps to install an older version of Node.js and npm on your system. What is NodeJS?Node is a JavaScript runtime(server-side) built on the
2 min read
How to Find the Version of an Installed NPM Package in Node.js ?
NPM is the default package manager for Node.js. NPM manages both internal and external packages or modules used in various Node.js applications. The default packages in NPM may not fulfil all the needs of a developer, so we often require external packages. These can be installed either locally in a
2 min read
How to Install and Manage Node using NVM on Godaddy Server ?
Managing multiple versions of Node.js on your server can be quite a task, especially if you're developing or maintaining applications that require different versions. Node Version Manager (NVM) simplifies this process by allowing you to install and switch between different versions of Node.js easily
3 min read
How to Install Yarn on Ubuntu 20.04
Yarn is a fast, reliable, and secure package manager for Node.js applications. It offers improved dependency management compared to npm, the default package manager for Node.js. In this beginner-friendly guide, we'll walk you through the step-by-step process of installing Yarn on Ubuntu 20.04, ensur
4 min read
How to list npm user-installed packages in Node.js?
What is Node.js? Node.js is an open source and cross-platform runtime environment for executing JavaScript code outside of a browser. Click here for more. What is npm? Here, "npm" stands for "Node Package Manager" which is the package manager for Node.js and serves as a command-line utility for inte
2 min read
How to Add Two Numbers in Console using Node.js ?
Adding two numbers using Node.js is a basic task that helps in understanding how to handle user input and process data within the Node.js environment. By following the steps in this guide, you'll learn how to create a simple Node.js application that reads numbers from the console, performs an additi
2 min read