Recently I broke my home-server and so I decided to reinstall all over again without using any kind of backup that kept my settings.

And not only because the last backup was so old o(╥﹏╥)o
Anyway, I really wanted to fix all the mess I've done in the previous server...

So I've decided to start with all the Environments, in this case: Node and npm.
All knows that is not a good Idea to use sudo npm install (if you use npm of course...)

So, if you want to try to run npm without sudo, let's get started!

If you already did a previous -g installation using sudo, we're going to fix it too.

First of all we need to see what packages need to be reinstalled by using:

npm list -g --depth=0

Now we need to get to install to our home directory

instead of using /usr/lib/node_modules or /usr/local/lib/node_modules ...

# You can change the directory...
npm config set prefix ~/npm

# To check if it works...
npm config get prefix

Now we need to fix the paths

# open .bashrc (Linux) or .bash_profile (Mac):
nano ~/.bashrc 
# or if you have zsh
nano ~/.zshrc

# add:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"

# To apply the updates...
source ~/.bashrc
# or
nano ~/.zshrc

Now we need to fix the previous installed packages

# to check if the folder is owned by root
ls -la ~/.npm

# set the ownership
sudo chown -R $USER:`id -g -n $USER` ~/.npm

Finally reinstall

# Now we need to retake the list we've got from the first command
# and reinstall everything. Just like:
npm install -g gulp

As you can see, no sudo required!


What can I say... I am @Nebulino... I like Anime, the Android world and all kawaii stuff... Don't think something strange... I like to dev too!