How to install Node.js on Linux

Node.js is a JavaScript runtime environment that is used for hosting websites. It offers users the ability to write websites in JavaScript whose code executes on the server instead of a client’s browser.

To host a website with Node.js on a Linux system, you need to download and configure the Node.js software. Node.js is available for installation on any major Linux distro, although the commands to install it may differ. Most users will also wish to install npm, the package manager for Node.js and JavaScript, when they install Node.js.

In this guide, we’ll show you how to install Node.js from the command line on various Linux distributions so you can get started hosting your JavaScript based website. We’ll also include instructions for installing npm.

In this tutorial you will learn:

  • How to install Node.js on major Linux distros
Checking the Node.js version and help menu on Linux

Checking the Node.js version and help menu on Linux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Node.js
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Node.js on major Linux distros

Use the appropriate command on your distribution to install Node.js. On some distributions, npm is installed along with the nodejs package. On others, the two packages are installed separately. The following commands will install both Node.js and npm. Feel free to omit the npm package when applicable, but most distributions will install it automatically as a dependency.

To install Node.js on Ubuntu, Debian, and Linux Mint:

$ sudo apt install nodejs
OR
$ sudo apt install nodejs npm

To install Node.js on CentOS 8 (and newer), Fedora, and Red Hat:

$ sudo dnf install nodejs # also installs npm


To install Node.js on CentOS 6, 7 and 8, and older versions of Red Hat:

$ sudo yum install epel-release
$ sudo yum install nodejs # also installs npm

To install Node.js on Arch Linux and Manjaro:

$ sudo pacman -S nodejs # also installs npm

To install Node.js on OpenSUSE:

$ sudo zypper install nodejs # also installs npm

Once Node.js is installed, you can begin using it to host your website, along with using npm to install any necessary JavaScript packages.

Conclusion

In this guide, we saw how to install Node.js, the JavaScript runtime environment, on all major Linux distributions. We also saw how to install the npm package manager, which goes hand in hand with Node.js and should usually be installed alongside it.



Comments and Discussions
Linux Forum