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.
What is Node JS?
Node.js 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.
What is NPM?
NPM 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. The registry stores the numerous JavaScript packages made available through the NPM CLI, along with their metadata. The NPM website 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.
There are several ways to install Node.js, but probably the most popular is using Node Version Manager (NVM).
What is NVM?
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).
Install
You can install NVM using cURL or Wget, you only need to execute one of the two commands in your terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | 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.
Usage
To install the latest version of Node.js, do this:
nvm install node # "node" is an alias for the latest version
To install a specific version of Node.js:
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):
nvm install --lts
Now just verify that Node.js and NPM are installed correctly, just run:
node -v # should return v16.13.0, v14.17.5, etc
npm -v # should return 8.1.2, 8.1.0, etc
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.
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.
Top comments (0)