Coding

Setting up a Virtual Machine for Node.js development on Windows 7


Hey, did you want to make $20k more/year by becoming a Full Stack PHP Programmer?
I've got a book for that! Want to learn more?

If you run Windows 7 and you want to develop for the latest version of Node.js, you’re in for a bumpy ride. You can compile it under Cygwin, but the process is complex and doesn’t work for all versions. So what if:

  • You fear a later version of Node.js breaking on Windows again? (It was broken for two full minor versions, really quite a while.)
  • You don’t want to install Cygwin? (You madman, you really should.)
  • You are paranoid and want to be running your programs on the same environment you will be deploying them on?
  • You just can’t get the dang instructions to work?

Well, the solution isn’t to reformat and install Linux (though that could very easily help your productivity – fewer games being played, I’m sure). The solution is to install Node.js on a Virtual Machine with a shared drive. And honestly? It’s pretty easy. Three steps!

Step One: Install VirtualBox

Download VirtualBox here, then follow the instructions.

Step Two: Install Ubuntu Server

Download Ubuntu Server here, then create a new Virtual Machine. Name it what you will.

Under the “Network” tab in settings, change the adapter to a “Bridged Adapter”. This will force the machine to get a locally-addressable IP address.

Under the “Shared Folders” tab in settings, click the “Add” button, set the folder path to some new folder on your Windows 7 system. Set the folder name to something simple like “nodejs”.

Under the “Storage” tab, click on the “IDE Controller”, then click the little CD button. Navigate to where you downloaded the Ubuntu Server ISO and select it.

Now boot your new Virtual Machine and follow the Ubuntu Server setup options. Install whatever your little heart desires, but I recommend an SSH server so you don’t have to install it later.

Once it’s installed, run the following commands to install VirtualBox Guest Additions:

sudo apt-get update
sudo apt-get install build-essential linux-headers-$(uname -r)
sudo apt-get install virtualbox-ose-guest-x11

Next, create a “nodejs” folder in your home directory, and add the following to your rc.local file (use the command “sudo nano /etc/init.d/rc.local”):

mount -t vboxsf nodejs /home/[YOUR_USER_NAME_GOES_HERE]/nodejs

Restart and your Windows folder should be hooked up to the nodejs folder on your Ubuntu VM.

Step Three: Install Node.js

This part’s super-simple. Run the following commands:

sudo apt-get update
sudo apt-get install git-core curl build-essential openssl libssl-dev
git clone https://github.com/joyent/node.git && cd node
./configure
make
sudo make install
node -v
cd
curl http://npmjs.org/install.sh | sudo sh

That’s it! You’re set up with Node.js and Node’s package manager, NPM. If you want to test it, go to your nodejs folder (in either Windows or Ubuntu, both should be working now) and make a file called “hello.js”, and put the following in it:

var sys = require('sys');
sys.puts('Hello!');

Then go to your Ubuntu system and run:

node hello.js

References

Thanks to Sysprobs and Giant Flying Saucer. It took a while to dig them up, but these two guides are what allowed me to figure out this neat little setup.


Coding
Code faster with simple Sublime Text improvements
Coding
Gulp.js – an AMAZING build system!
Coding
Rage-quit support for fish shell
  • paul

    paulpaul

    Author

    great! worked like a charm.

    one typo… missing ‘s’ on sudo:
    udo apt-get install virtualbox-ose-guest-x11


  • Dan Hulton

    Dan HultonDan Hulton

    Author

    Fixed! Thanks.


  • ben

    benben

    Author

    Works great! thanks!


  • Dan Hulton

    Dan HultonDan Hulton

    Author

    My pleasure.


  • pinksy

    pinksypinksy

    Author

    Perfect!


  • Dave

    DaveDave

    Author

    This advice left me with an ubuntu server which is unreachable via HTTP from my Windows machine. The shared folders work, but “curl THE_IP_ADDR” returns “curl (7) couldn’t connect to host”. Is there a firewall that needs to be disabled? Could you update that article with the normal nodejs “hello world” http server example?


  • Dave

    DaveDave

    Author

    The http server from this guy’s site (http://chrisfulstow.com/running-node-js-on-windows-with-virtualbox-and-ubuntu) works. I changed the listen method from listen(1337, “127.0.0.1”) to listen(8888). I should have realized that specifying the loopback device (as in the example on nodejs.org) would prevent me from visiting the url from my windows machine.


  • Dave

    DaveDave

    Author

    … and I also disabled the firewall (sudo ufw disable). Dan, feel free to condense my comments. Sorry for the spam.


  • Dan Hulton

    Dan HultonDan Hulton

    Author

    It’s cool, it’s not spam if it’s legitimate issues that folks are coming across.


  • Corey

    CoreyCorey

    Author

    Thanks for the post. I did have an issue with the build not supporting ‘sudo make install’ and I had to force a version of node with:
    git checkout v0.6.x (x being whatever the most current supported build)
    this can be checked with:
    git tag -l
    while sitting in your clone directory.

    I am pretty new to these processes so I couldn’t tell you how to implement this in your process.


  • Jay

    JayJay

    Author

    Good post. Just a small correction, I’m running node v0.7.8-pre and it says:
    The “sys” module is now called “util”


  • John Lindquist

    It’s working great, just a quick question:

    I’m trying to have “coffee” watch the Shared Folder for changes to my .coffee files and recompile on change.

    If I edit the file and save in Windows, it doesn’t recompile. If I edit the files and save in Ubuntu, it recompiles fine.
    (same goes for “less” watching changes)

    Any ideas?


  • Dan Hulton

    Dan HultonDan Hulton

    Author

    I wish I could help you on this, but I long ago switched to OSX for development. Everyone else in the office uses one, so I stopped fighting the tide.

    My guess is this is a VMWare issue though – the filesystem not reporting as “changed” when altered by remote host. Maybe try updating your version of VMWare, or ask on their forums?


  • Anton Stoychev

    Well, this doesn’t solve anything besides installation of node on Ubuntu/Debian.

    How are you going to make symlinks work on the shared drives?

    Main part of nodejs development is todo with packages that are trying to generate symlinks. One of the main is “express” web framework.

    I am yet to find a solution on this. You can maybe use git and push the files from the host (Windows 7) to the guest ( ubuntu) to the ubuntu virtual hard disk. But otherwise symlinks will never work.


  • Dan Hulton

    Dan HultonDan Hulton

    Author

    I confess, I switched long ago to a Macbook where I can just run Node locally without any Virtualbox shenanigans. While I found a workaround or trick I could use for nearly all my problems on Windows, on OSX or Linux, you can usually just directly and easily do what you set out to in the first place.