Node.js installation is a simple task. We just need the right steps. In this tutorial, we shall learn to setup environment for Node.js and the prerequisites to start developing Node.js applications.
Download the latest binary distribution from [https://nodejs.org/download/release/latest/]. Based on the Operating System and Architecture, download a suitable package. The size would be less than 20MB.
Following are the latest packages available at the time of writing this tutorials (for x64) :
Once the download is complete, extract the package and include it in the system path variable.
Go to the downloaded folder, Open a Terminal from there and execute the following commands.
Unzip the compressed package
~$ tar xvfz node-v8.4.0-linux-x64.tar.gz
Make nodejs directory in
/usr/local/. Replace the file name, if it is different from what you have downloaded.
~$ sudo mkdir -p /usr/local/nodejs
Move the extracted nodejs package to
/usr/local/nodejs/. Provide user password if asked.
~$ sudo mv node-v8.4.0-linux-x64/* /usr/local/nodejs/
Add the path
/usr/local/nodejs/bin to PATH environment variable. Provide user password if asked.
.bashrc file and append the nodejs’ path at the end. To edit .bashrc, open a terminal and run the following command :
~$ sudo nano ~/.bashrc
Add the following line at the end of
$ export PATH=$PATH:/usr/local/nodejs/bin
Once after adding the line, close the terminal and reopen again.
To verify if nodejs path has been added to PATH environment variable, run the following command :
~$ echo $PATH
For Windows OS, the value echoed back should have
For installing Node.js on Windows Operating System, double click on the .msi file and follow the prompt step by step. Finishing the prompt should install Node.js with PATH added to the environment variables.
Using a Text Editor, create a sample file with name
verifyNode.js and copy paste the following content to that file.
console.log("Hi there! This is Node.js!")
And run the following command in Command prompt or Terminal from the directory of
verifyNode.js script file.
$ node verifyNode.js
Hi there! This is Node.js!
Following is the syntax to run a Node.js file using node command line interface :
~$ node <file_name>
In this Node.js Tutorial, we have learnt to install Node.js on a computer and verify the installation by executing a sample script(.js) file.