Install Node.js on Linux

  1. Install Node.js via package manager
  2. Install Node.js from NodeSource
  3. Install Node.js using Node Version Manager(NVM)
Method-1. Install Node.js using Package Manager
On Arch Linux:
sudo pacman -S nodejs npm
On Debian, Ubuntu, Linux Mint:
sudo apt-get install nodejs npm
On RHEL, CentOS:
sudo yum install epel-release
sudo yum install nodejs npm
On Fedora:
sudo dnf install nodejs npm

Note: Since the packages from the default repositories are outdated, you will get the following error when you try to install any NodeJS modules using npm.

/usr/bin/env: ‘node’: No such file or directory

To solve this error, you need to create symlink as shown below.

sudo ln -s /usr/bin/nodejs /usr/bin/node
Method-2. Install Nodejs from NodeSource
On Debian, Ubuntu distributions:
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install nodejs npm
On RHEL, CentOS:
curl --silent --location https://rpm.nodesource.com/setup_9.x | sudo bash -
yum install nodejs npm
Method-3. Install Nodejs using NVM (Recommended method)
NVM (Node Version Manager) is a bash script used to manage multiple Node.js versions.
  • This is the best way to avoid permissions issues.
  • It allows us to install, uninstall node.js, and switch from one version to another.
  • Good thing is we can install to any available Node.js version of our choice, using NVM.