How to run an IDE INSIDE a Vagrant VM

Vagrant is intended as a runtime environment for use with your development, not as the development environment (IDE, tools, etc) itself. But I thought it would be nice if I could run my IDE inside the VM. This would have several advantages, including: leverage IDE shortcuts for executing the app, make it easier to connect the debugger, and ease ramp up time for other developers.

So I looked into setting up a Vagrant VM with Netbeans. The necessary steps are downloading and installing Netbeans in a provisioner, and forwarding X11 from the VM to the Host.

There are many options to do silent installation of Netbeans. I had this inside my shell provisioner (note, this takes quite a while to download and install, and you should do this after installing java)

chmod 755
sudo ./ --silent -J-Dnb-base.installation.location=/opt/netbeans-7.3
To do X11 forwarding requires a few steps
  • Add to Vagrantfile: config.ssh.forward_x11 = “false”
  • run vagrant with “vagrant up –no-provision” so you don’t download netbeans again!
  • vagrant ssh into the VM, running netbeans brings up the UI on your host display, it “just works!”

At this point, it works but performance is horrible. Clicking on a menu in Netbeans takes about 12 seconds to respond.

To improve the performance, we can specify a faster cipher and compression for X11. To specify this, connect with ssh directly instead of using vagrant ssh so we can pass in the ssh options. Use vagrant ssh-config to configure ssh to connect to the vagrant VM:  vagrant ssh-config > ~/.ssh/config (be careful not to blow it away if that file already exists). The command looks like ssh -F ~/.ssh/config -c arcfour,blowfish-cbc -XC default  Note that the ssh config is set to “Host default” and we need to specify that (“default”) in the ssh command. Using localhost in the ssh command will not work. After this change, performance is much better but still bad (response time opening menus goes from 12 seconds to 4 seconds)
Additional things to try include manually modifying the VM video RAM to 64MB from 8, but that had no effect. (Indeed another VM I use for development that has the full gnome desktop installed and regularly run an IDE with no issue has only 12MB of video RAM) Another initially promising option was to enable VirtualBox 2D acceleration, but that is for Windows guests only so is not an option for Linux guests.
More potential steps you can take to improve the performance
  • VMWare’s provider is rumored to have special graphics optimizations that let you work with an IDE inside a VM.
  • You can try VRDP, it may have better performance than X11
  • NX Server is supposed to be faster than X11

In conclusion, using Vagrant as your complete development environment does not really work out as well as you’d hope. Perhaps not so surprisingly, it’s best to use Vagrant as it was intended.


Filed under Software Engineering

6 responses to “How to run an IDE INSIDE a Vagrant VM

  1. antonmos

    I have the same setup, and Intellj is working quite well in a Centos6 guest on MacbookPro i7.
    I wonder if it’s a problem with Netbeans specifically

    • Jason Young

      Thanks for the info, I should give it a try with some other applications.

      • antonmos

        Upon further usage, i did see some lag when intellij loaded large classes. I could see the colorization happen briefly and it was enough to bug me.
        After a whole bunch of research i found a live fork of Nomachine, called X2GO. It makes it easy to start apps in a floating window (just like x-forwarding) and performs really well (pick 16m-png compression)

        Hope this helps!

      • antonmos

        One more thing to remember – Virtualbox shared folders have really bad IO performance. Virtualbox does allow you to set up shared folders using NFS which performs better. But the fasted disk performance (i.e. compilation/test execution/etc) can be achieved only by putting the workstpace on the virtual drive. This can be annoying if you actually want to be able to ‘vagrant destroy’, and then resume development on a new version of the os, without having to resetup everything in the home directory. I found vagrant-persistent-storage plugin that allows to mount another virtual disk which wont get destroyed.

      • Jason Young

        That’s a handy tip, thanks!

  2. Kev

    I’d be very curious to know if you get this working in eclipse

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s