Pages

Tuesday, October 13, 2015

How To Install Node.js (latest version) in Linux

How To Install Node.js (latest version)
On Linux

Introduction:

Node.js :

Nodejs is an open source, cross platform , JavaScript runtime environment which is based on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.
It is used to develop scalable, real-time, network and server-side applications written in javascript and we can run that applications within Node.js runtime environment on OS X, Windows, Linux, solaris and BSD.

Node.js provides an event-driven architecture and a non-blocking I/O API designed to optimize an application's throughput and scalability for real-time web applications. It uses Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in library to allow applications to act as a web server without software such as Apache HTTP Server, Nginx or IIS.

Node.js can be combined with a browser, a document database (such as MongoDB or CouchDB) and JSON for a unified JavaScript development stack.

According to wikipedia,
Node.js is used by IBM, Microsoft, Yahoo!, Walmart, LinkedIn, Rakuten, PayPal and GoDaddy.

npm :

npm is the pre-installed package manager for the Node.js server platform. It is used to install Node.js programs from the npm registry, organizing the installation and management of third-party Node.js programs.

Installtion :

For Debian and Ubuntu based distributions :

You can install the Distro-Stable Version from official repositories of your distribution ,by just running apt-get install package name in your linux command line.

sudo apt-get update && sudo apt-get install nodejs && sudo apt-get install npm

Latest versions of Nodejs providing npm as default package manager. So we dont need to install it seperately in latest versions of Node.Js.

but, there may be a chance that your distribution's official repositories may contain only older version of node js.
if u want to install latest version of nodejs(at the time of writing this post 4.x is latest version of nodejs), then you need to use node source PPA.

curl -sL https://deb.nodesource.com/setup_4.x | sudo bash -

or

wget -qO- https://deb.nodesource.com/setup_4.x | sudo bash -

Note : For example if you want to install Node.Js 6.x, Replace 4.x with 6.x. (i.e) replace it with version you want to install.



Update (Latest available LTS version of Nodejs ..)

wget -qO- https://deb.nodesource.com/setup_6.x | sudo bash -

Update (Latest available version of Nodejs ..)

wget -qO- https://deb.nodesource.com/setup_7.x | sudo bash -

After running above command, run the follollowing commands..

sudo apt-get -y install nodejs

during or after installation, if you experience any errors run this command and try again:

sudo apt-get -y install build-essential && sudo apt-get -f install

Remember.. If you are doing nodejs installation using nodesource ppa, you need not to run sudo apt-get install npm. Because npm comes along with node installation.. so don't run sudo apt-get install npm, if you are doing nodejs installation with from nodesource ppa.. otherwise if you run above command after installing nodejs from nodesource ppa, you would see error message or warning message thrown by your distributions package-manager.. don't worry about that message.. Just ignore it and enjoy NodeJS
HAPPY NODE ! .

For RPM based systems..

sudo curl --silent --location https://rpm.nodesource.com/setup_4.x | bash - && sudo yum -y install nodejs

For Fedora 22 and later versions..

sudo curl --silent --location https://rpm.nodesource.com/setup_4.x | bash - && sudo dnf -y install nodejs

Note : For example if you want to install Node.Js 6.x, Replace 4.x with 6.x. (i.e) replace it with version you want to install.

For Arch Linux

Node.js and npm packages are available in the Community Repository.

pacman -S nodejs npm

Compiling from source..

For Linux before start to compile install following packages..

sudo apt-get install g++ curl libssl-dev apache2-utils git build-essential

Step 1 :Clone source code from git repo..

cd && git clone https://github.com/nodejs/node.git

If you are using OS X you have to install git and X Code , before start to compile..

Or , simply download code as zip file from NodeJS git Repo and extract it

Step 2 : Now change directory (navigate into) to downloaded directory

cd ~/node

Step 3 : Now run compile it..

./configure && make && sudo make install

For more specific version installation instructions see here... and You can find installation instructions for more distros in official wiki.