Site icon Treehouse Blog

How to Install Node.js and NPM on Linux

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

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:

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.

Exit mobile version