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
Wedding Dress Trends 2024: Bridal Elegance and Fashion Forward Styles - Karen Willis Holmes
Outsourcing Contracts: Best Practices For Business Growth | Blog
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Jackerman Mothers Warmth Part 3
Manhattan Prep Lsat Forum
Pitt Authorized User
Aiken County government, school officials promote penny tax in North Augusta
craigslist: south coast jobs, apartments, for sale, services, community, and events
Yi Asian Chinese Union
Nesb Routing Number
Here's how eating according to your blood type could help you keep healthy
Xrarse
Minn Kota Paws
Oppenheimer & Co. Inc. Buys Shares of 798,472 AST SpaceMobile, Inc. (NASDAQ:ASTS)
Hello Alice Business Credit Card Limit Hard Pull
litter - tłumaczenie słowa – słownik angielsko-polski Ling.pl
Oriellys St James Mn
2021 Lexus IS for sale - Richardson, TX - craigslist
Costco Gas Foster City
The Shoppes At Zion Directory
ᐅ Bosch Aero Twin A 863 S Scheibenwischer
Les Rainwater Auto Sales
Missouri Highway Patrol Crash
Talbots.dayforce.com
Little Caesars 92Nd And Pecos
Jeffers Funeral Home Obituaries Greeneville Tennessee
If you have a Keurig, then try these hot cocoa options
Vernon Dursley To Harry Potter Nyt Crossword
Boise Craigslist Cars And Trucks - By Owner
Turbo Tenant Renter Login
Pensacola Tattoo Studio 2 Reviews
Jurassic World Exhibition Discount Code
Lacey Costco Gas Price
Rays Salary Cap
Beth Moore 2023
Weekly Math Review Q4 3
Craigslist West Seneca
Games R Us Dallas
20 Best Things to Do in Thousand Oaks, CA - Travel Lens
Aliciabibs
Felix Mallard Lpsg
Noaa Duluth Mn
22 Golden Rules for Fitness Beginners – Barnes Corner Fitness
VerTRIO Comfort MHR 1800 - 3 Standen Elektrische Kachel - Hoog Capaciteit Carbon... | bol
Lorton Transfer Station
Ratchet And Clank Tools Of Destruction Rpcs3 Freeze
Wood River, IL Homes for Sale & Real Estate
Is Chanel West Coast Pregnant Due Date
Besoldungstabellen | Niedersächsisches Landesamt für Bezüge und Versorgung (NLBV)
Free Carnival-themed Google Slides & PowerPoint templates
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.