banner



How To Install Node Js With Nvm

install node.js on linux

Node.js is an open-source, free, cross-platform JavaScript run-time environment which is responsible for executing JavaScript lawmaking on server. It allows developers to use JavaScript for server-side scripting - running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser. Consequently, Node.js represents a "JavaScript everywhere" paradigm, unifying web awarding development around a single programming linguistic communication, rather than different languages for server side and client side scripts.

In this tutorial, I volition show you how to install the latest Nodejs on Ubuntu 18.04, CentOS 7, and Curvation Linux from the terminal.

There are several ways to install Node.js on Linux car and we are going to cover them in this article.

  • Install using Node Version Manager (NVM)
  • Install using the Github source code clone
  • Install the Distro-Stable version of Node.js

Install using Node Version Manager (NVM)

NVM doesn't work at the operating organisation level, instead information technology works at the level of a directory within your user's home directory. It allows installing multiple, cocky-contained versions of Node.js without affecting the entire system.

Ubuntu xviii.04

Before installing NVM we update Os with the post-obit command

          sudo apt-become update        

To use nvm, we must have curl, build-essentials libssl-dev packages installed on the system. To install them type

          sudo apt-get install build-essential libssl-dev        

Once all prerequisites are available we install nvm with the following command

          curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.xi/install.sh | bash        

The script in a higher place clones the nvm repository to ~/.nvm and also adds the source line to your contour (~/.bash_profile, ~/.profile or ~/.bashrc). That means we need to source the profile file. To practice so, type the following control

          source ~/.profile        

Now nvm functionalities and binaries are available for use and nosotros can get list of available Node.js versions via the following command

          nvm ls-remote        

Tail of output must look like the one below:

          ...  v9.6.0  v9.6.1  v9.seven.0  v9.7.ane  v9.eight.0  v9.nine.0  v9.ten.0  v9.10.1  v9.11.0  v9.11.1  v10.0.0        

Choose the version you want to install and type the command below to install it.

          nvm install v9.10.1        

After installing the desired version we tin set that version every bit default Node.js version (in case you accept multiple installations)

          nvm use v9.10.1        

To check if version is installed and set to default successfully, just cheque Node.js version with the control below

          node -v        

or

          nvm electric current        

The output of this command must show the installed version.

To update/install another version you can run:

          nvm install v10.0.0        

Make sure to run the command with the version you want to install. After you can set the freshly installed version equally your default with the following control:

          nvm use v10.0.0        

To remove node.js version via nvm, starting time check if it's not the current version with the command beneath

          nvm current        

and run the following control to remove the desired version:

          nvm remove v9.ten.1        

CentOS vii

The procedure of installation of nvm and node.js using nvm is the same equally on Ubuntu 18.04 with few differences. Below you can detect commands running which in the same order volition install nvm, node.js and set up the default version.

Update Os

          sudo yum update        

Install nvm

          curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.xi/install.sh | fustigate        

Source profile file (notation that in CentOS it differs from the one in Ubuntu)

          source ~/.bashrc        

List available node.js versions

          nvm ls-remote        

Install the desired version (make certain to change with the version yous want to install)

          nvm install v9.x.1        

Set as default node.js version

          nvm use v9.10.1        

Check if installation and default setting are succeeded

          node -v        

or

          nvm current        

To update/install some other version you can run:

          nvm install v10.0.0        

Make sure to run the command with the version you want to install. After yous tin set the freshly installed version as your default with the post-obit command:

          nvm use v10.0.0        

To remove node.js version via nvm, first check if it's not the electric current version with the command below

          nvm current        

and run the following command to remove desired version:

          nvm remove v9.10.1        

Install using the Github source code clone

To install Node.js using release from official Github repository we need to check make sure the brand, gcc, g++ and python packages are installed on Ubuntu 18.04 motorcar. If there are missing packages, you lot can run:

          sudo apt-get install make gcc m++ python        

On CentOS vii all needed packages are preinstalled in Bone. Y'all can run OS update command to brand sure they are latest versions:

          sudo yum update        

The rest part of installation using GitHub repository'south official release is the same for both distributions.

Download the desired release (e.g. v6.2.1) from Github Repo using the following control:

           wget https://github.com/nodejs/node/annal/v6.2.ane.tar.gz        

Excerpt the content of the archive using the command below

          tar zxvf v6.2.1.tar.gz        

Enter the directory with extracted files

          cd cd node-half dozen.2.1        

and run the following control to compile

          ./configure        

Afterward compilation you can now install node.js using the following command:

          sudo make install        

The process of installation tin can take piddling bit longer this mode. It depends on resources of your machine.

Install the Distro-Stable version of Node.js

In default repositories of Linux distributions, there are versions of Node.js and you tin can install them using any package managing director of the distribution (apt for Ubuntu, yum for CentOS and etc...). The main issue with this type of installation is that the versions available in official repositories may be outdated. For example, at the moment of writing this tutorial the latest version of Node.js in Ubuntu's repositories is v8.10.0, and in CentOS epel-release repo the latest available version is v6.fourteen.0. Only using nvm we can install v10.0.0 at the same time. However, below you tin observe steps to install latest available stable version of Node.js for each distro.

Ubuntu 18.04

Before installing Node.js on your Ubuntu 18.04 auto, update yous Os to the latest version. To practice so, yous tin run:

          sudo apt-go update        

Now you tin can install Node.js using the following command:

          sudo apt-get install nodejs        

Also you tin install npm (Node.js bundle director) to install modules and packages. To install npm, run the control below:

          sudo apt-become install npm        

Later on installation, you can bank check the version of Node.js (note that the executable from the Ubuntu repositories is called nodejs instead of node)

          nodejs -five        

To update Node.js on Ubuntu xviii.04 motorcar either update OS with the command:

          sudo apt-get update        

or run install command. Information technology will update the existing version if there are updates:

          sudo apt-go install nodejs        

To remove Node.js from your Ubuntu 18.04 machine run the following command:

          sudo apt-get remove nodejs        

CentOS 7

To install Node.js on CentOS 7 auto using official repositories follow the steps below.

Start, install epel-release repository on your motorcar using the following command:

          sudo yum install epel-release        

This will let you to install Node.js. To practice so, you can run:

          sudo yum install nodejs        

Cheque the installed version with the command below:

          node --version        

And finally you can install npm (Node.js parcel manager) using the following command:

          sudo yum install npm        

To update Node.js on CentOS 7 motorcar either update Os with the command:

          sudo yum update        

or run install command. It will update the existing version if there are updates:

          sudo yum install nodejs        

To remove Node.js from your CentOS7 car run the post-obit command:

          sudo yum remove nodejs        

Arch Linux

To install Node.js on Arch Linux, use the following command:

          sudo pacman -S nodejs        

To install npm, you can run:

          sudo pacman -S npm        

To remove Node.js from Arch Linux typ:

          sudo pacman -R nodejs        

Bank check if Node.js is working using script

To check if our installation (doesn't matter which mode) is successful and node.js is working properly, we are going to create very simple "Hi Globe" app and check if everything works fine. To practise so, nosotros create hello-world.js in our home directory file using the command below:

          vim hullo-earth.js        

and add the following content into information technology and save the file:

          a="Howdy"; b="World!"; console.log( a+' '+b);        

At present we run the app with the post-obit command

          node hello-world.js        

The output must be the one shown beneath

          Hello Earth!        

That means that node.js is installed correctly and working properly. Y'all can at present go ahead and create your incredible apps using node.js.

Testing With Node.JS Beat

Let'due south commencement with the node control as follow and get its output effect to see if Node.JS is fully functional.

          # node > console.log('Node.js Installed Using Packet Managing director'); Node.js Installed Using Package Director        

REPL For Your NodeJS Apps

REPL is the Node.js trounce, any valid Javascript which can be written in a script can be passed to the REPL. So let'due south see how REPL works with NodeJS.

          root@ubuntu18:~# node > var repl = require("repl"); undefined > repl.start("> ");  Press Enter and it will show out put similar this: > { domain: null, _events: {}, _maxListeners: 10, useGlobal: false, ignoreUndefined: false, eval: [Part], inputStream: { _connecting: simulated, _handle: { fd: 0, writeQueueSize: 0, owner: [Circular], onread: [Function: onread], reading: true }, _readableState: { highWaterMark: 0, buffer: [], length: 0, pipes: null, ... ...        

Here is the list of command line help that we can use to work with REPL.

REPL Manual

Working with NodeJS Packet Manager

NPM is uncomplicated CLI tool for ensuring that a given node script runs continuously. It helps to Install and manage dependencies through the file package.json. Nosotros will start its using init command as.

          # npm init        

npm init
Conclusion

If you want to use the verbal version of Node.js the better mode is to install using nvm or cloning from Github official repository. If there is no affair which version to use 1 can install using distro's default package manager, every bit that fashion is much faster than the others.

Read Besides:

  • How to Remove and Add PPA on Ubuntu xviii.04

Source: https://linoxide.com/install-nodejs-linux/

Posted by: haskinsneard1957.blogspot.com

0 Response to "How To Install Node Js With Nvm"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel