How to install Node js on Linux
Tags: npm, node, linux, bash
Published: 2021-11-03 22:41:18

When we start using Linux, one of the first doubts is how to install our favorite applications. As developers, we need several tools, one of the most common is Node.js and NPM. Let's see what is Node.js, NPM and how to install them in Linux.
<br />

## What is Node JS?
[Node.js](https://nodejs.org/) is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser. Node.js is a popular, lightweight web framework for beginners, and it is used by many big companies like Netflix and Uber.
<br />

## What is NPM?
[NPM](https://www.npmjs.com/) is the default package manager for Node.js projects. NPM includes a command-line tool (CLI) that give you access to the [NPM package registry](https://docs.npmjs.com/cli/v7/using-npm/registry). The registry stores the numerous JavaScript packages made available through the NPM CLI, along with their metadata. The [NPM website](https://www.npmjs.com/) gives you an easy way to search for JavaScript packages and read information about them. The `package.json` file that is generated by the NPM CLI helps you manage project dependencies. It also ensures consistent project installations across environments.
<br />

There are several ways to install Node.js, but probably the most popular is using Node Version Manager (NVM).
<br />

## What is NVM?
[NVM](https://github.com/nvm-sh/nvm) allows you to quickly install and use different versions of Node via the command line. Is a version manager for Node.js, designed to be installed per-user, and invoked per-shell. NVM works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash).
<br />

## Install
You can install NVM using cURL or Wget, you only need to execute one of the two commands in your terminal:
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
```

```bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
```
To verify that it is installed correctly just type `nvm -v` and it should return the latest version of NVM, for example `0.38.0`. To upgrade NVM, just run the same command.

There are some times that when we finish installing NVM, we run `nvm -v`, and instead of getting something like `0.38.0` we get `nvm: command not found`. But it is not the end of the world, in these cases it is necessary to close our terminal, open a new one and try `nvm -v` again.
<br />

## Usage
To install the latest version of Node.js, do this:
```bash
nvm install node # "node" is an alias for the latest version
```
To install a specific version of Node.js:
```bash
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
```
To install the long-term support (LTS) of Node.js (the one I recommend):
```bash
nvm install --lts
```
<br />

Now just verify that Node.js and NPM are installed correctly, just run:
```bash
node -v # should return v16.13.0, v14.17.5, etc
```

```bash
npm -v # should return 8.1.2, 8.1.0, etc
```
<br />

And that's it! We already have Node.js and NPM in our Linux in a quick and easy way.
For more information check the NVM repository, there is more advanced information, frequent problems, and also where you can report a bug.
<br />

If you know other/better way please leave below in the comments. Share this post to whoever you think will help. I'll see you later.