How to Install Node.js and NPM on Linux [Guide] | Treehouse Blog (2024)

Andrew Chalkley
writes on January 15, 2020

JavaScript is used everywhere today. From its birthplace in the Netscape browser in the mid-nineties, it’s made its way into all modern web browsers, onto mobile phones, and into electronics to make full-fledged web applications on the server-side with Node.js.

Node.js is non-blocking, which means it’s ideal for creating real-time web applications such as chat servers, analytics, collaboration tools, and interactive games.

In order to create such applications, you’ll need NPM a package manager for Node. It allows you to download and install open source JavaScript libraries that help you make awesome applications.

Prerequisites Before Installing

  • You should have some familiarity with the Linux terminal since you’ll need to use it to install and test Node and NPM. You’ll also need the terminal to use Node.js and NPM.
  • Dependencies. You need to install a number of dependancies before you can install Node.js and NPM.
    1. Ruby and GCC. You’ll need Ruby 1.8.6 or newer and GCC 4.2 or newer.
      • For Ubuntu or Debian-based Linux distributions, run the following command in your terminal: sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev Then select Y to continue and wait for the packages to be installed.
      • For Fedora based Linux distributions run the following command in your terminal application: sudo yum groupinstall 'Development Tools' && sudo yum install curl git m4 ruby texinfo bzip2-devel curl-devel expat-devel ncurses-devel zlib-devel Then select Y to continue and wait for the packages to be installed.
    2. Homebrew. Homebrew is a package manager originally for the Mac, but it’s been ported to Linux as Linuxbrew, making installing most open-source software (like Node) as simple as writing: brew install node You can learn more about Homebrew at the Homebrew website and Linuxbrew at the Linuxbrew website. To install Homebrew for Linux, open your terminal application and paste in the command: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)" Follow the instructions in the terminal to complete the installation process.

Once Linuxbrew is installed, you’ll need add the following 3 lines to your .bashrc or .zshrc file:

 export PATH="$HOME/.linuxbrew/bin:$PATH" export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH" export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"

Why Homebrew/Linuxbrew?

You may be asking why you should use a third-party package manager. Here are some advantages:

  • Can install software to a home directory and so does not require sudo
  • Install software not packaged by the native distribution
  • Install up-to-date versions of software when the native distribution is old
  • Use the same package manager to manage both your Mac and Linux machines

Installation

Installing Node.js and NPM is pretty straightforward using Linuxbrew, the Linux port of Homebrew. It handles downloading, unpacking, compiling, and installing Node and NPM on your system. After you have Linuxbrew installed, the whole process should only take you a few minutes.

  1. Open up your terminal and type brew install node.
  2. Sit back and wait. Homebrew has to download some files, compile and install them. But that’s it.

How to Check Node.js on Linux

Make sure you have Node and NPM installed by running simple commands to see what version of each is installed:

  • Test Node.js. To see if Node.js is installed, type node -v in the terminal. This should print the version number, so you’ll see something like this: v0.10.35.
  • Test NPM. To see if NPM is installed, type npm -v in the terminal. This should print the version number, so you’ll see something like this: 2.1.17

How to Update Node and NPM on Linux

New versions of Node and NPM are released frequently. You can use Homebrew to update the software it installs.

  1. Make sure Homebrew has the latest version of the Node package. In Terminal type:
    brew update
  2. Upgrade Node: brew upgrade node

How to Uninstall Node and NPM

You can also use Homebrew to uninstall packages that it installed:

brew uninstall node

Other Platforms

Thanks to Dave McFarland, as he wrote some installation guides to install Node.js and NPM on Mac (which this guide heavily borrows from) and Windows.

Conclusion

Now that you have Node.js and NPM installed, you can build an awesome application with Node.js, or use one of the Node packages like Grunt or Gulp to improve your front-end workflow.

If you’re looking to take your JavaScript coding to another level, check out the Treehouse Techdegree in Full Stack JavaScript. Our faculty of tech professionals guide learners like you from mastering the fundamentals of JS to polishing the skills of a job-ready developer. Try our program out with a free seven-day trial today.

GET STARTED NOW

Learning with Treehouse for only 30 minutes a day can teach you the skills needed to land the job that you've been dreaming about.

Get Started

  • code
  • javascript
  • mobile
  • node.js

21 Responses to “How to Install Node.js and NPM on Linux”

  1. Julian on October 19, 2017 at 7:16 am said:

    Really good article! Just an update, the linux homebrew repo has recently moved to http://linuxbrew.sh/

    Log in to Reply

  2. Lojban on August 8, 2017 at 4:46 am said:

    This article presents a heavyweight solution that didn’t work for me.

    After hours downloading everything, Linuxbrew didn’t work to install Node, finally giving some error about not being able to use/locate Perl, even though it is definitely installed on the Ubuntu 16 system.

    I eventually found NVM to install NPM which was so much faster and easier: https://stackoverflow.com/a/39981888

    Log in to Reply

  3. Alex on November 17, 2016 at 9:35 am said:

    Please add in this to the instructions between adding the 3 export PATHS and brew install node:

    brew update

    from:
    https://github.com/Homebrew/homebrew-core/issues/2494
    (bottom of page)

    Nice tutorial man, (for those who want to do JS development but still wont get a mac!)

    Thanks

    Log in to Reply

  4. Gracjan on August 9, 2016 at 8:46 am said:

    maybe check out this :
    https://gist.github.com/GracjanZwr/112de571d939e5a4dff5ab97a400afae
    let me know if everything is working and in right order 😉
    peace !

    Log in to Reply

  5. Maleon on August 3, 2016 at 4:18 am said:

    Thanks a lot buddy, really helpfull

    Log in to Reply

  6. G on June 4, 2016 at 11:22 pm said:

    Good post. I tested with Fedora 23 and works fine!.
    However, I think you should add one line. Always, before try to install node, run the command.
    brew update
    Otherwise you will have errors or inconsistencies in your installation.

    Log in to Reply

    • no-name on September 23, 2016 at 4:58 am said:

      Brew is “The missing package manager for Mac OS” , there is a Linux version but I would recommend using apt, apt-get or rpm depending on your Linux distribution instead of brew 😉 .

      Log in to Reply

  7. E on December 16, 2015 at 7:36 pm said:

    Well using the above list of dependencies, i looked at installing it on OpenSuse 13.1 but it wants to install 1476 NEW packages, most of which are called texlive – not gonna happen – thats foolish. There is no way that ANY package can require that much in dependencies.

    Log in to Reply

  8. Mouhanad Chebib on November 21, 2015 at 10:13 am said:

    On GoDaddy hosting:
    – I had both Ruby and GCC, with the minimum versions installed.
    – I installed Homebrew (linuxbrew) at `~/.linuxbrew` and it is installed with version 0.9.5.

    When trying to install NodeJS with `brew install node`, I am getting an error:
    “`
    nice: /usr/local/bin/ruby: No such file or directory
    Error: Suspicious failure
    “`

    When checking my ruby installation, `which ruby` it is here /usr/bin/ruby.

    Please advise.

    Log in to Reply

  9. Fogathajtó Döntő on September 16, 2015 at 4:28 am said:

    “Any reason this is called Linux but more specific to Mac?”

    No. gcc and (home)brew is running w/o any problem on my osx too.

    Log in to Reply

  10. Alex on August 25, 2015 at 11:51 am said:

    I was able to successfully install these items, however now when I try to check for a version of node (node -v in terminal) or when I try a brew command (brew install….) I get a command not found “brew” error message. Any idea what happened to my installation?

    Thanks for your help ~Alex

    Log in to Reply

    • Alex on August 25, 2015 at 11:52 am said:

      Sorry, the error message for $~node -v is “the program ‘node’ can’t be found…”

      Log in to Reply

  11. Shane on August 18, 2015 at 3:24 pm said:

    Any reason this is called Linux but more specific to Mac?

    Log in to Reply

  12. Vladimir Dumitraskovic on January 27, 2015 at 4:36 pm said:

    On vagrant (trusty32 – Ubuntu 14.04), i use something like:
    apt-get -y install curl
    curl -sL https://deb.nodesource.com/setup | sudo bash –
    apt-get -y install nodejs

    Just my 0.02 🙂

    Log in to Reply

  13. 21coders on January 25, 2015 at 12:05 am said:

    Complicated thing like node.js made easy, Thanks.

    Log in to Reply

  14. Marcus on January 22, 2015 at 7:31 pm said:

    If you’re using at least Ubuntu 14.04 (not sure about earlier versions), **nodejs** resides within the default repositories. You can just run `sudo apt-get install nodejs` and `sudo apt-get install npm`.

    Log in to Reply

    • Vladimir Dumitraskovic on January 27, 2015 at 4:37 pm said:

      Somewhat true. Default Ubuntu 14.04 repo uses old node version.

      Log in to Reply

  15. Martin Page on January 16, 2015 at 5:05 am said:

    Great image choice for an article about Linux 😉

    Log in to Reply

  16. Jacklyn on January 15, 2015 at 4:20 pm said:

    Finally a post about node.js, its really complex but you managed to make it sound easy, thanks a lot.

    Log in to Reply

Leave a Reply

You must be logged in to post a comment.

How to Install Node.js and NPM on Linux [Guide] | Treehouse Blog (3)

Are you ready to start learning?

Learning with Treehouse for only 30 minutes a day can teach you the skills needed to land the job that you've been dreaming about.

Start a Free Trial

How to Install Node.js and NPM on Linux [Guide] | Treehouse Blog (4)

How to Install Node.js and NPM on Linux [Guide] | Treehouse Blog (2024)

FAQs

How to Install Node.js and NPM on Linux [Guide] | Treehouse Blog? ›

js and NPM is pretty straightforward using Linuxbrew, the Linux port of Homebrew. It handles downloading, unpacking, compiling, and installing Node and NPM on your system. After you have Linuxbrew installed, the whole process should only take you a few minutes. Open up your terminal and type brew install node .

How to install Node.js and npm on Linux? ›

Installing Node.js on Ubuntu:
  1. Open a terminal window.
  2. To make sure you get the most recent details about the packages that are available, update the package list: sudo apt update.
  3. Install Node.js and npm using the package manager: sudo apt install nodejs npm. ...
  4. Verify the installation by checking the versions:
Dec 7, 2023

How to install Node.js in Linux step by step? ›

Using Ubuntu's official repository

Follow the steps below to install Node. js on your Ubuntu operating system. Step 1: Open your terminal or press Ctrl + Alt + T. Node and NPM will be successfully installed on your Ubuntu machine.

How to install Node.js and npm on Ubuntu? ›

Method 1: Using Official Repository for Node. js and npm Installation on Ubuntu
  1. Step 1: Open Terminal Window.
  2. Step 2: Run the Command.
  3. Step 3: Create a Symbolic Link.
  4. Step 4: Check if node.js and npm is installed or not.
  5. Step 1: Install Curl.
  6. Step 2: Curl the Directory.
  7. Step 1: Install NVM.
  8. Step 2: Check if NVM is Installed.
Jun 26, 2024

How to install Node.js and npm on rhel? ›

Before that we have to verify that wget is already installed to the server or not because we need to use that command to download the Binaries file.
  1. Install the wget (if you haven't) yum install wget.
  2. Unzip and install under /usr/local folder. cd /usr/local. ...
  3. Verify the Node version. node -v. ...
  4. Verify the NPM version. npm -v.
Mar 16, 2021

How do I download and install Node.js and npm? ›

In a web browser, navigate to the Node.js Downloads page. Click the Windows Installer button to download the latest stable version with long-term support (LTS). The installer also includes the NPM package manager. The file is saved in the Downloads folder by default.

How to install Node.js with terminal? ›

Let's follow the given steps and install Node.
  1. Step 1: Download NVM with Install Script. Now, you have two options to install NVM. ...
  2. Step 2: Verify NVM Installation. You can verify NVM with the given command: ...
  3. Step 3: Install the Latest Node Version Using NVM. Run the given command to install the latest version of Node.js.
Feb 14, 2024

What is the command for npm install? ›

Use the npm install command with the ? save-dev option and the following syntax to accomplish this: npm install <package_name> --save-dev.

How to install Node.js correctly? ›

Installation of NodeJS and NPM is straightforward using the installer package available at NodeJS official web site.
  1. Download the installer from NodeJS WebSite.
  2. Run the installer.
  3. Follow the installer steps, agree the license agreement and click the next button.
  4. Restart your system/machine.

What is npm in Linux? ›

npm is a package manager for Node. js projects made available for public use. Projects available on the npm registry are called “packages.” npm allows us to use code written by others easily without the need to write them ourselves during development.

How to check if Node.js is installed? ›

To see if Node is installed, open the Windows Command Prompt, Powershell or a similar command line tool, and type “node -v”. Note: This should print the version number so you'll see something like this v0.

How to install node and npm using nvm? ›

Install Node using NVM
  1. Install a target Node. js version. A short version will do. ...
  2. Select the installed version. $ nvm use 14 Now using node v14.9.0 (npm v6.14.8)
  3. Check that your target Node. js version works. ...
  4. List available installed versions. $ nvm ls v10. ...
  5. List versions which can be installed. $ nvm ls-remote.

How to install Node.js binaries in Linux? ›

Installing Node.js via binary archive on Linux
  1. Unzip the binary archive to any directory you wanna install Node. sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C $PATH-NODEJS.
  2. Set the environment variable `~/.profile`, add below to the end. # Nodejs. ...
  3. Refresh profile. . ...
  4. Test installation using.

How to install npm js in Linux? ›

Install Node. js and npm from the Ubuntu
  1. Step 1: Update Package Lists. The first step is to update the package lists on your Ubuntu system. ...
  2. Step 2: Install Node. js. ...
  3. Step 3: Verify the Installation. ...
  4. Step 4: Manage npm Versions (Optional) ...
  5. Step 5: Install Global Packages (Optional) ...
  6. Step 6: Update the npm.
Dec 5, 2023

How to install Node.js file in Linux? ›

The example below specifies the command-line entries for the Ubuntu distribution.
  1. Step 1: Install the build tool prerequisites. sudo apt update sudo apt install make g++ libssl-dev git.
  2. Step 2: Download the Node. js source files. ...
  3. Step 3: Configure and build the solution. ...
  4. Step 4: Test and confirm.

How to update Node.js and npm in linux? ›

Follow the steps below to update Node.js using NPM:
  1. Clear the npm cache: npm cache clean -f.
  2. Install n , Node's package manager: npm install -g n.
  3. With the n module installed, you can use it to:
Jan 31, 2024

How to install npm and node in git bash? ›

Steps are as follows:
  1. Install Git on your computer.
  2. Set up some of the basic global configurations for Git.
  3. Installing Node.
  4. Complete the set up of Node. js and NPM on your machine.
  5. Verify that the installation was successful and your machine is ready for using Node. js and NPM.
Jan 11, 2020

How to run Node.js with npm? ›

Installation of NodeJS and NPM is straightforward using the installer package available at NodeJS official web site.
  1. Download the installer from NodeJS WebSite.
  2. Run the installer.
  3. Follow the installer steps, agree the license agreement and click the next button.
  4. Restart your system/machine.

How to install specific node and npm version? ›

You can run the npm update specific package command with a specific package name to update a specific package. Also, in some cases, to update a package to a specific version, you must use the npm install command with a version number followed by the package name.

Can I use Node.js on Linux? ›

n is a simple to use Node.js version manager for Mac and Linux. Specify the target version to install using a rich syntax, or select from a menu of previously downloaded versions. The versions are installed system-wide or user-wide, and for more targeted use you can run a version directly from the cached downloads.

Top Articles
How To Fix Tinder Account Under Review in 2024?
Revised Guidelines Redefine Birth Years and Classifications for Millennials, Gen Z, and Gen Alpha
Affidea ExpressCare - Affidea Ireland
Videos De Mexicanas Calientes
Mylaheychart Login
Computer Repair Tryon North Carolina
Www.megaredrewards.com
Jesse Mckinzie Auctioneer
Concacaf Wiki
1TamilMV.prof: Exploring the latest in Tamil entertainment - Ninewall
Mndot Road Closures
Bubbles Hair Salon Woodbridge Va
Guardians Of The Galaxy Vol 3 Full Movie 123Movies
Hair Love Salon Bradley Beach
Conan Exiles Colored Crystal
Bnsf.com/Workforce Hub
Dr Adj Redist Cadv Prin Amex Charge
Cyndaquil Gen 4 Learnset
Satisfactory: How to Make Efficient Factories (Tips, Tricks, & Strategies)
Aps Day Spa Evesham
Tyler Sis University City
Menards Eau Claire Weekly Ad
The Weather Channel Local Weather Forecast
Employee Health Upmc
Lost Pizza Nutrition
Rapv Springfield Ma
Taylored Services Hardeeville Sc
Primerica Shareholder Account
Life Insurance Policies | New York Life
Ofw Pinoy Channel Su
Teenbeautyfitness
Skroch Funeral Home
Powerball lottery winning numbers for Saturday, September 7. $112 million jackpot
Wow Quest Encroaching Heat
Best Workers Compensation Lawyer Hill & Moin
Page 5662 – Christianity Today
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
How are you feeling? Vocabulary & expressions to answer this common question!
Tiny Pains When Giving Blood Nyt Crossword
Barber Gym Quantico Hours
'Guys, you're just gonna have to deal with it': Ja Rule on women dominating modern rap, the lyrics he's 'ashamed' of, Ashanti, and his long-awaited comeback
Gym Assistant Manager Salary
US-amerikanisches Fernsehen 2023 in Deutschland schauen
How I Passed the AZ-900 Microsoft Azure Fundamentals Exam
Valls family wants to build a hotel near Versailles Restaurant
Flappy Bird Cool Math Games
bot .com Project by super soph
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
The Latest Books, Reports, Videos, and Audiobooks - O'Reilly Media
March 2023 Wincalendar
28 Mm Zwart Spaanplaat Gemelamineerd (U999 ST9 Matte | RAL9005) Op Maat | Zagen Op Mm + ABS Kantenband
Phumikhmer 2022
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 5892

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.