Menu

How to install node.js with Ubuntu and Vagrant in a synced folder

Recently, I’ve had to work on a project using AngularJS and node.js. Development was eased using a Ubuntu 14.04 virtual machine, through Vagrant. Not a big deal to install, I was saying to myself, except I ran into a ton of errors with my very naïve approach (geez, what an optimistic fool I can be sometimes).

By running a remote nodesource script and installing g++, I am now able to have a more recent version of node.js (0.12.7) and npm (2.11.3), which are more up-to-date (as of today) and cause less issues with node.js packages. Also, as most of you probably know, node.js was initially invoked through the command “node”, conflicting with another binary with the same name, and as a consequence was later renamed as “nodejs”. The node.js version installed with nodesource makes node.js available through the “node” and “nodejs” commands, resolving issues with a couple of node.js packages (PhantomJS, I’m pointing at you).

By creating a symbolic link for “node_modules” to a directory outside of the Vagrant synced folder, I got rid of filesystem failures from the node.js packages.

For Windows host users, by running the “vagrant up” command as administrator, I allowed them to create symbolic links in a Vagrant synced folder

Bonus

All of the above commands in a single Vagrantfile, working, free, just for you, because development should always be like unicorns and rainbows: