nodejs in Linux (CentOS): compilation and installation from source

Third party dependency libs

sudo yum groupinstall "Development Tools"

Note: Development Tools contains various 3rd party libs to compile and build new rpm from the source.

If above command does not install any lib in your machine, then you may try the following command, (In my machine, Development Tools did not install anything).

sudo yum groupinstall "Additional Development"

Compilation and installation steps

Download the nodejs from the official site: https://nodejs.org/en/download/

1) Create node-4.1.2 installation directory in the /opt with proper read/write/executable permission
     i.e: /opt/node-4.1.2

2) Run the following commands in the downloaded source folder of node:

     2.1) sudo ./configure --prefix=/opt/nodejs-4.1.2
     2.2) sudo make install

Note: 

You may want to add more option during configuring process. To see more options: 
     ./configure --help

In my case, I kept default settings. I just configured my desired installation directory.

You may want to install nodejs in different directory. In this case, you have to change --prefix value to your desire nodejs installation directory path instead of /opt/nodejs-4.1.2.

3) Create node_home.sh file in /etc/profile.d folder:

      #NODE_HOME
      export NODE_HOME="/opt/nodejs-4.1.2"
      export PATH=$NODE_HOME/bin:$PATH

4) Logged out or restart the machine
 
5) Update npm: npm install -g npm. (Depending on permission, you may need to use sudo/su command)

Yes! your are done. nodejs is installed successfully with updated npm (if update available).

Comments

Popular posts from this blog

There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server; ERROR

How to install Homebrew in Mac OSX (High Sierra)

WildFly 19 and Log4J2