On a recent episode of the Giant Robots Smashing Into Other Giant Robots podcast, Ben Orenstein said that when you’re learning something new, you should write the blog post you wish you could have read. This is one of those blog posts.
At the recent RogueRails workshop, we were given a Vagrant/VirtualBox setup to work from. I wanted to use RubyMine with this configuration, but I wasn’t sure how to do it. In the end, I was able to get it working, but the laptop I was using didn’t have the horsepower to run both a VM and RubyMine at the same time so I didn’t use it for the workshop. Afterwards, I tried again on my more powerful desktop machine.
The VM we were using was set up to use RVM and to NFS mount the
project directory as
/vagrant on the VM.
Here’s what I did to get things working.
First, I followed the
instructions in the RubyMine documentation
to set up a remote SDK. I had to change the Ruby interpreter path to
point at the Ruby we were using under RVM. To find out where that
was, I used
vagrant ssh -c "which ruby".
Once I did this, RubyMine attempted to load the list of Rake tasks and Rails generators, but failed in both cases because it couldn’t find my Gemfile. It was looking in the path from my local computer, not the path in the VM.
I then found
this video from JetBrains
which gives the same information as the documentation, but also talks
about configuring the VM for “Deployment”. That was an important
step. I added a new Deployment for my VM using SFTP as described in
the video. I set the root path to
/ on the Connection tab, and
configured a mapping from my local directory to
/vagrant on the VM
on the Mappings tab. Since our VM was NFS-mounting the project
/vagrant already, there is no actual deployment
required, but this lets RubyMine know where to find things in the VM.
I then tried to
bundle install using RubyMine, but that failed
because RubyMine attempts to run Bundler using my local machine’s
path, not the remote machine’s path. This is a
known bug in
RubyMine 184.108.40.206.1. Apparently, it’s fixed in the EAP versions of
RubyMine 6, but I haven’t tried that yet. I could run
install on the VM manually, but RubyMine doesn’t make use of the
results for some reason. I believe that this is because it doesn’t
yet support RVM on remote machines, but I’m not sure about that,
because I have a similar problem on my local machine.
To work around the bug, I created directories on the VM to match the
path on my local machine with a symbolic link to
This workaround works on OS/X and Linux, but I’m not sure how well it would work on Windows because of drive letters. My guess is that it would be possible to create a path on the VM that looks like a full Windows path including the drive letter and it would work, but I haven’t tried that.
I tried running
bundle install from within RubyMine again. It got
further, but failed with a “Permission denied” error. It was trying
to write into the RVM gems directory. To fix this, I
sshed into the
VM and ran:
With that done, I was able to successfully
bundle install from
RubyMine. I was then able to develop using RubyMine like I normally
If this were a real project, I’d likely build these extra manual steps into the Vagrant/VirtualBox setup for the project rather than having to do them manually every time.
I’m actually pleasantly surprised that RubyMine supports this workflow as well as it does. There are some kinks to work out, but it sounds like they’re being fixed in the next version of RubyMine. If there’s a way to improve on what I’ve done here, I’d love to hear about it.