Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active February 20, 2017 09:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leommoore/4420651 to your computer and use it in GitHub Desktop.
Save leommoore/4420651 to your computer and use it in GitHub Desktop.
Installing and Compiling Node.js

#Node - Installing and Compiling Node.js

##Simple Install Ubuntu

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

##Compile and Install

###Amazon Linux

sudo yum install gcc gcc-c++ openssl-devel curl

###Ubuntu

sudo apt-get install g++ libssl-dev apache2-utils curl make libkrb5-dev

###Compiling

sudo apt-get update
sudo apt-get install -y python-software-properties g++ make
mkdir /usr/src/node && cd $_
#wget -N http://nodejs.org/dist/node-latest.tar.gz
wget -N http://nodejs.org/dist/v6.7.0/node-v6.7.0.tar.gz
#tar xzvf node-latest.tar.gz && cd `ls -rd node-v*`
tar xzvf node-v6.7.0.tar.gz && cd `ls -rd node-v*`
#cd node-latest
cd node-v6.7.0
sudo ./configure
sudo make install

###Node Version No.

node --version

###Node Documentation

man node

###Important Security Note Node comes with the npm package manager. It is strongly encouraged that you should not to do package management with sudo. Packages can run arbitrary scripts which makes them a potential security risk.

It is recommended that you give your user account access to the /usr/lib/node_modules folder instead:

sudo chown -R $USER /usr/local
sudo chown -R $USER /usr/lib/node_modules

sudo mkdir -p /usr/local/{share/man,bin,lib/node,include/node}
sudo chown -R $USER /usr/local/{share/man,bin,lib/node,include/node}

That sets your user account as the owner of the /usr/lib/node_modules directory, so that you can just issue normal commands in there. Then you won’t ever have to use sudo when you install node or issue npm commands.

###Set up npm directory

npm config set prefix ~/npm

Then add $HOME/npm/bin to $PATH by appending the following to .bashrc

export PATH="$PATH:$HOME/npm/bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment