Node JS / NPM have become essential parts of many applications. Because of this, and my recent experience with Node, I have decided to compile some instructions on how to install Node JS/NPM so that you do not require the sudo command (I found I needed this constraint when using

Node JS / NPM have become essential parts of many applications. Because of this, and my recent experience with Node, I have decided to compile some instructions on how to install Node JS/NPM so that you do not require the sudo command (I found I needed this constraint when using Ember-CLI).

The Problem

Note: this tutorial was run on XUbuntu 14.04 (Ubuntu) & OSx Mavericks

There are many valid ways to install Node and NPM, so if you know of a different method that works for you by all means, stick with that. This tutorial on installing Node/NPM is directed towards those who have run into the unbearable EACCES errors when trying to:

install npm

use npm install (for packages such as bower, etc.)

etc.

I spent quite a bit of time searching for solutions to this dilemma. It seemed for a while that I would have to run npm with sudo, but I knew that would just cause issues down the road.

Many solutions suggested modifying permissions, using sudo chown -R 'whoami' [directory] or other permission commands, in order to give your user the appropriate permissions to run npm and it's packages without sudo. Unfortunately even modifying the permissions didn't always solve my problem.

Pre-requisites:

Before following the steps below to install node/npm, you should make sure that there are no prior existing versions of node/npm on your system. There are several ways to see if you have node/npm installed on your system. I prefer to use the following commands to show where node/npm exist if they are present on your system:

$ which node
$ which npm

If there is no output after either of the above, then that respective package is not present on your system (whether it be node or npm).

If it does not, I suggest taking a quick gander at the linked article.

Removing node is a bit more tedious, at least I found it to be. The way I went about it was to simply purge my system of all folders that referenced node. I followed the step listed in this StackOverflow answer. I won't restate the answer as it is fairly brief and just involves removing a few folders.

Note: if you installed node to your home directory the files will likely be in a different location than listed in the linked answer (in your home directory instead of the root).

There are other solutions for removing node/npm out there so feel free to leave a comment with any other solutions, or concerns.

The Solution

Fortunately I stumbled on a solution that did not require modified permissions. We will use the Node Version Manager (NVM) to install Node/NPM. The installation instructions are on their linked page, but I will re-state them in this post so that all the instructions to get Node & NPM working are in one concise page for you.

I've also included instructions, specifically for OSx, on how to install Node with Homebrew. These instructions are mostly just referenced from other posts, which I have added links to in the References section. I've included these because using Homebrew on OSx is very popular and convenient.

Installing With NVM

First, open a terminal window and enter one of the following commands:

Once you've run either of those commands and NVM has finished downloading, run the following command:

$ source ~/.profile

Now NVM commands should be working in the terminal, try $ nvm to confirm the NVM command is working. If not, try restarting your terminal.

Once NVM is working you can install a version of node by using the following command:

$ nvm install [version-no]

To list the available versions, run this command:

$ nvm ls-remote

Although, I find it preferrable to check which is the current version on NodeJS. The current version, at the time of writing this article, is v0.10.29. To install this version run:

$ nvm install 0.10.29

You check which version of Node NVM activated by entering the following command:

nvm current

To check in general what version of Node is being used, use this command:

node -v

To check in general what version of NPM is being used, use this command:

npm -v

If you run the

$ which node

command you will see that node is installed in your home directory which is okay for the development of applications. In fact, from what I've experienced so far it is preferrable in some cases. You don't have to deal with permission errors and modifying permissions of root folders. However, once you've moved into production it is recommended that node get moved into a global/root location, as to prevent the client from modifying important configurations.

Installing with homebrew (OSx)

This portion is for OSx users only, I assume you already have installed homebrew on your machine. If not, visit the site for instructions: HomeBrew

This portion is heavily referenced from another blog, as I am not the most familiar with OSx & homebrew

If there are any questions, recommendations or concerns feel free to leave a comment below, or message me on Twitter @TylerWen. I will consistently alter/add to this article to ensure the solutions are relevant with on-going changes.

A new blog, what I should say is my first blog. I've never blogged before besides spamming pictures of radiohead to my old Tumblr account. This is a bit more of a mature approach in comparison to what I used to consider a blog. I have wanted to start a

A new blog, what I should say is my first blog. I've never blogged before besides spamming pictures of radiohead to my old Tumblr account. This is a bit more of a mature approach in comparison to what I used to consider a blog. I have wanted to start a blog for a while, but for some reason or another I was not very attracted to any of the blogging platforms I had come accross. It was due to my recent dabbling in the EmberJS framework that led me to Ghost. I was pretty intrigued when I found out Ghost was running on EmberJS; however, the real hook was that it is open source and I had been looking for an opportunity to make contributions to the open source community. Yay for open source!

What I plan to talk about

Although this blog will be mostly ramblings on many different topics; here are a few things I plan to talk about:

Software Development

I am heading into my 4th year of my Bsc Computing Science and am currently working as a Systems Developer Intern, so I plan on focussing mainly on topics regarding software, the development process, different frameworks, things that generally interest me in the development world.

Programming Tutorials

I love coding, and I want you to too. If I pick up a new skill or find a solution to a problem that I think could help others, it is likely that I will post a explanation/tutorial on my blog. So tune in every once and a while for a quick tip!

Student Life

As I mentioned above, I am heading into my 4th year of the Bsc Computing Science program at the University of Alberta. I'm also an intern for the first time in my life. All this is pretty exciting to me so there is a good chance that I will chat about either of these things in the future.

New Technology - All Things Cool

I am always interested in cool new technology. We live in an exciting time when technology has become a relevant part of everyone's life. Constantly changing, evolving; it makes for an exciting topic.

General Speak

Most importantly, I plan on using this blog as a place where I can just think and talk. I'm not an overly vocal person so sometimes it's nice to talk to a blank canvas. Which is why I wanted to create a blog in the first place!

So here goes nothing! I hope you, whoever you are, enjoy what I have to say.