We will see how to install Node.js and NPM in Linux in an easy and fast way, we will do it by installing NVM (Node Version Manager).
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.
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).
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).
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.
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
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.
Thank you for reading 🙏
If you enjoyed this article or found it helpful, share this post to whoever you think will help, and if you know other/better ways please leave discuss on Twitter.
Feel free to connect 👋