NodeJS is an open source, cross-platform, and lightweight JavaScript run-time environment that can be used to build scalable network applications. It is fast and efficient server-side software built on Chrome’s V8 JavaScript engine. Initially, JavaScript was primarily used for client-side scripting. But, Nodejs enables JavaScript to be used for server-side scripting, and runs scripts server-side to produce dynamic web pages. Another notable thing is Nodejs has a command-line utility called npm, a package manager to install, manage nodejs libraries and applications. Nodejs package ecosystem is the largest ecosystem of open source libraries in the world.
NodeJS v10.0.0 has been released yesterday. It is the seventh major nodejs release since the launch of NodeJS foundation. This major release ships with some prominent features as listed below.
Install NodeJS on Linux
There are quite a few ways to install Nodejs. The first method is for those who wants to use the stable NodeJS version. The second method and third methods can get you the latest available versions. In particular, the third method is the best way to avoid permission issues while installing packages globally. I will explain all of them.
1. Install Nodejs using your distribution’s package manager (Stable, but outdated versions)
Nodejs 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:
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.
To solve this error, you need to create symlink as shown below.
2. Install Nodejs from NodeSource
Like I already said, nodejs is available in the default repositories, but it might be bit outdated. To install the most recent version, install the latest version from NodeSource as shown below.
On Debian, Ubuntu distributions:
Add Nodejs 8.x repository:
For Nodejs 9.x:
Then, install Node.js using command:
On RHEL, CentOS:
Run the following command as root user to add Node.js v8 LTS repository:
To add Node.js v9 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:
3. Install Nodejs using NVM (Recommended method)
This is yet another way to install Nodejs. This is the best way to avoid permissions issues. NVM (Node Version Manager) is a bash script used to manage multiple Node.js versions. 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.
To install nvm, use the latest install script from here:
Or,
The above command will clone the nvm repository to ~/.nvm and add the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
Sample output will be:
Restart your Terminal once before start using NVM.
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/update to 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 v9.3.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 v10.0.0.
If you have installed more than one version, you can 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:
No comments:
Post a Comment