Install nodejs - lightblueseas/linuxstuff GitHub Wiki

First add NodeSource PPA.

To use version Node.js v5.x:

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

Fixing npm permissions

For a detailed description follow this link.

They are two options for do that here is the first option.

We will change the permission to npm's default directory:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Note: If you get error that node_modules folder not exists you can create it.

sudo mkdir -p $(npm config get prefix)/lib/node_modules
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Thats it. If this is not an option for you use the second option that is described in the following section.

Changing the npm's default directory to another directory

The second option is the following.

create a directory in your home directory:

mkdir ~/.npm-global

Tell npm to use the new directory:

npm config set prefix '~/.npm-global'

Export the bin directory by inserting following line in your ~/.profile:

export PATH=~/.npm-global/bin:$PATH

Update with:

source ~/.profile

If you see next time by start the shell following message:

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? 

Than run following commands for fix this:

cd /usr/local/share/zsh
sudo chmod -R 755 ./site-functions