How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (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.

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (1)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (2)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (3)

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.

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (4)

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.

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (5)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (6)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (7)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (8)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (9)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (10)

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:

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (11)

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.



P

protonwcnz

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (12)

Improve

Next Article

How to Install Node.js on a Webserver ?

Please Login to comment...

How to Install Node.js and npm on Ubuntu? - GeeksforGeeks (2024)
Top Articles
5 Ways to Unlock the Root (Money) Chakra
Customer Service Expectations: 8 Things Every Consumer Wants
Katie Nickolaou Leaving
Pixel Speedrun Unblocked 76
Roblox Roguelike
Tyrunt
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Locate Td Bank Near Me
Where's The Nearest Wendy's
今月のSpotify Japanese Hip Hopベスト作品 -2024/08-|K.EG
Med First James City
Summoners War Update Notes
How Much Is Tj Maxx Starting Pay
What is Rumba and How to Dance the Rumba Basic — Duet Dance Studio Chicago | Ballroom Dance in Chicago
NHS England » Winter and H2 priorities
Prosser Dam Fish Count
Unity - Manual: Scene view navigation
Ahrefs Koopje
Accident On The 210 Freeway Today
Robeson County Mugshots 2022
Sussyclassroom
Jail View Sumter
Brbl Barber Shop
O'reilly's In Monroe Georgia
897 W Valley Blvd
Maths Open Ref
Does Royal Honey Work For Erectile Dysfunction - SCOBES-AR
N.J. Hogenkamp Sons Funeral Home | Saint Henry, Ohio
APUSH Unit 6 Practice DBQ Prompt Answers & Feedback | AP US History Class Notes | Fiveable
Solve 100000div3= | Microsoft Math Solver
Old Peterbilt For Sale Craigslist
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
Despacito Justin Bieber Lyrics
Clark County Ky Busted Newspaper
Nsav Investorshub
Doordash Promo Code Generator
Puretalkusa.com/Amac
Panorama Charter Portal
Achieving and Maintaining 10% Body Fat
Traumasoft Butler
Winta Zesu Net Worth
What to Do at The 2024 Charlotte International Arts Festival | Queen City Nerve
Crystal Glassware Ebay
Greg Steube Height
Myapps Tesla Ultipro Sign In
6463896344
Game Like Tales Of Androgyny
Secondary Math 2 Module 3 Answers
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
La Fitness Oxford Valley Class Schedule
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6113

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.