Installing node.js on Vagrant

I wanted to share this Vagrant bootstrap file which installs the latest version of node on Vagrant – it took me a while to figure this out when I was getting started with Vagrant, which is probably just a reflection of my elementary unix skills. Anyway, here’s the bootstrap file:

sudo apt-get update
sudo apt-get install python-software-properties -y
sudo add-apt-repository ppa:chris-lea/node.js -y
sudo apt-get update -y
sudo apt-get install nodejs -y
sudo apt-get install build-essential g++

And because this is aimed at beginners here’s the Vagrant file for reference too!

Vagrant.configure("2") do |config|
  config.vm.box = "precise32"
  config.vm.provision :shell, :path => 'bootstrap.sh'
  config.vm.network :forwarded_port, guest: 80, host: 8080
end

Simply pop these 2 files in a new directory, name them bootstrap.sh and Vagrantfile respectively, and then exec the vagrant up command in your terminal and you will have a new node.js development environment to play with – excellent!