How To Install Node.js On Linux
Node.js is an open source, cross-platform, and lightweight JavaScript run-time environment that is used to build scalable network applications. It is fast and efficient server-side software built on Chrome’s V8 JavaScript engine. As you may already know, initially, JavaScript was primarily used for client-side scripting. But, Node.js enables JavaScript to be used for server-side scripting, and runs scripts server-side to produce dynamic web pages. Another notable thing is Node.js has a command-line utility called npm, a package manager to install, manage nodejs libraries and applications. Node.js’ package ecosystem is the largest ecosystem of open source libraries in the world.
In this tutorial, we will see how to install Node.js on major Linux operating systems including Arch Linux, Debian, Ubuntu, RHEL, CentOS, Fedora etc.
Install Nodejs on Linux
There are quite a few ways to install Nodejs. I will explain all of them.
Install Nodejs using your distribution’s package manager
Node.js is available in the default repositories of most Linux distributions. It might not be latest version, but stable. If you want to have a stable Node.js on your Linux, you better install it using your distribution’s package manager as shown below.
On Arch Linux and its derivatives like Antergos, Manajaro Linux, run the following command to install it:
On Debian, Ubuntu, Linux Mint:
On RHEL, CentOS, you need to enable EPEL repository first.
And, then install Nodejs using command:
On Fedora:
Install Nodejs from NodeSource
Even though, nodejs is available in the default repositories, it might be bit outdated. To use the most recent version, install the latest version from NodeSource as shown below.
On Debian, Ubuntu distributions:
Add Nodejs 6.x repository:
For Nodejs 7.x:
Then, install Node.js using command:
On RHEL, CentOS:
Run the following command as root user to add Node.js v6 LTS repository:
To add Node.js v7 repository:
To add Node.js 0.10 repository:
Then install, as root:
For Fedora, follow the same instructions above.
Install build tools (Optional)
To compile and install native addons from npm repository, you may also need to install build tools.
To install build tools on Debian, Ubuntu distributions, run the following command:
On RHEL based systems:
On Fedora:
Recommended Download – Free eBook: “Simply JavaScript ($29 Value FREE For a Limited Time)”
Install Nodejs using NVM
Alternatively, you can install Nodejs using NVM (Node Version Manager). It is a bash script used to manage multiple released Node.js versions. Using NVM, you can install any available Node.js version of your choice. NVM allows us to install, uninstall node.js, and switch from one version to another.
To install nvm, run the following command as root user:
The above command will clone the nvm repository to ~/.nvm and add the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
Then, source the .bash_profile as root user:
NVM has been installed now. To verify whether NVM is installed or not, run:
Sample output:
It should output ‘nvm’ if the installation was successful.
Now, we can install Nodejs and npm.
First, run the following command to view the list of available Nodejs versions:
Sample output:
To install the most recent Nodejs version, just run:
Alternatively, you can run the following to install any Nodejs version of your choice.
For example, to install Nodejs v7.9.0, run:
Sample output:
Similarly, you can install any number of versions you want.
To view the list of installed Nodejs versions, run:
Sample output:
As you see in the above output, I have installed two versions v7.8.0 and v7.9.0. And, v7.9.0 is the default version, and v7.8.0 is the currently active version.
You can also switch between different Nodejs versions as below.
Or you can just run it to be more specific:
To set a particular Nodejs version as the default, run:
Sample output would be:
To remove the particular Nodejs version, run:
Sample output:
To view the currently installed and default Nodejs version, run:
Or,
Sample output:
Check npm version:
Sample output:
And, that’s all. You know now how to install Nodejs on your Linux distribution. As you can see, installing Nodejs is fairly easy. Anyone can install and setup the Nodejs within few minutes.
Cheers!
Resources:
No comments:
Post a Comment