Ask A Question

Notifications

You’re not receiving notifications from this thread.

Using Vagrant for Rails Development Discussion

Chris Oliver asked in General

Trying to install the librarian-chef plugin first produces an error about not being able to find the vmware-workstation plugin (or rather gem). Installing the vbguest plugin first fixed the issue.

Reply

Thanks! I'll be sure to update that.

Reply
Carlo DiCelico Carlo DiCelico

Awesome post! I had a ton of trouble installing the plugins, though. In case anyone else has the same issue, where installing plugins fails and you see a bunch of stuff about nokogiri, let me save you some Googling. Just see https://github.com/mitchell... for the cure!

Reply

Ouch, that's kind of nasty. I hope they get that fixed soon. Thanks for sharing the link!

Reply

Nice and simple, great tutorial. Any idea how I can do this behind a proxy (that requires auth).... I live in a corporate environment :(

Reply

That's a good question. I would imagine you could set a system proxy on your OS and your network traffic would flow through there. Hopefully that would take care of routing all the downloads through there without having to configure a proxy inside the Vagrant guest machine too.

Reply
Joel Taylor Joel Taylor

Perhaps I'm missing something, but is there a reason you didn't include Rails in the Cheffile?

Reply

That's what Bundler is for. Your version of Rails is application specific, so you let Bundler manage it with your app's Gemfile.

Reply

I'm stuck at this part when I run 'vagrant up'. I'm on Windows Environment.. Help?

Reply

Is it actually causing you problems? I know the "stdin: is not a tty" seems to be more of a warning than an actual problem according to this https://github.com/mitchell...

I haven't run this on Windows yet however, so keep me posted if things don't work after finishing the tutorial. This is a very long thread but someone mentions the error and you might find a solution in here: https://github.com/mitchell...

Reply

Same error here, did you manage to solve it?

Reply
Anthony Candaele Anthony Candaele

I'm having the same issue, and I'm on a Mac X (Mavericks) environment. Not sure if it's doing something and if I should wait.

Reply

This is interesting. I use VMware's Workstation for my vm, but haven't tried these tools. So are you suggesting a different vm for each dev/production project, and this is the quick way to set up the environment for each? I've just been running a bunch of projects in one vm. Reasons I shouldn't do that?

Reply

This is going to setup a separate VM for each mainly for the purpose that everyone working on the project starts with a clean machine. If you don't run into any problems with your setup, you don't really need this. The trouble comes in when you need to share your machine setup with say 50 other developers. Then you need something like this so everyone can spin up a development environment without any trouble.

Reply

I have been trying to figure out how vagrant works for a few hours. Just bumped into your article. This was very helpful and well explained. Thanks! I will be modifying the Chef portion to use http://phlippers.net/chef-p..., but other than that it was spot on for me.

Thanks. Keep it up.

Reply

I failed at step first: setup vagrant plugins. Here is an error i get:

Thanks for wanting to use Vagrant! Unfortunately, this is not the way
to install Vagrant anymore. We now make installers for the various operating
systems Vagrant supports.
Vagrant is no longer distributed as a RubyGem. Please download the latest
version for your operating system from the URL below. If you still wish
to use the RubyGem version, you can manually install version 1.0.7. Note that
the RubyGem version hasn't been updated in over a year and will no longer
receive any updates.

Prior to installing Vagrant using the installer, make sure you uninstall
all your Vagrant gems, since they sometimes conflict.
http://www.vagrantup.com
If you want to learn more about why we don't distribute using RubyGems
anymore, please read this: http://mitchellh.com/abando...

Reply

Did you install Vagrant from the rubygem before? I linked to the installer and make sure you remove the Vagrant gem.

Reply

Nice article. Will you consider to add docker for this tutorials?

Reply

Most definitely!

Reply

So there's a nasty gotcha if you're using Windows 8.1, which I believe is tied to having installed the Windows Phone dev tools - this will enabled Hyper-V by default which will silently ruin any attempts you make to run a x64 VirtualBox VM, or so I've experienced. I just had SSH time out, and then a black screen when I attempted to boot with GUI.

This post details a way to get around that: https://www.hanselman.com/b...

Not ideal, I might see if I can get this to use a x86 machine instead, if possible, and be sure to test on a x64 before production.

If you don't actually do any WP development, you can alternatively uninstall the Hyper-V components from your system, and be problem free.

Reply

Thanks for posting this Chris. I got all the way to the end and when I run `rails server` I get this error:

vagrant@vagrant-ubuntu-trusty-64:/vagrant$ rails server
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0
Ask your administrator to install one of them

I ran `rbenv rehash` and then tried `rails server` again and everything works!

One other thing I learned through working this post: I have vmware_fusion as a Vagrant provider plugin, so I need to specify virtualbox when I `vagrant up --provider=virtualbox`

Great article!

Reply

Thanks for the tips Dave! :)

Reply

isn't there a cart before the horse problem here? You can't run rails new projectname until you have rails installed?

Reply
Kartik Danidhariya Kartik Danidhariya

i get same problem i run rbenv rehash ant then tried 'rails server'
but it still return
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0
Ask your administrator to install one of them
pls help i am new for vagrant and ROR
Thanks in advance!!!

Reply
Daniil Garmoshka Kucherenko Daniil Garmoshka Kucherenko

# After vagrant installed & provisioned, run inside vm:

cd /vagrant

gem install bundler
gem install rails -v 4.2.1
rbenv rehash
bundle

Reply
Александр Пурхало Александр Пурхало

1. sudo gem install bundler
2. bundle
3. bin/rails server -b 0.0.0.0

This should help you to deal with this problem.

Reply
Gruff Davies Gruff Davies

I've added a port forward to my host 3306 to 23360 in the vagrant file so I can access MySQL using Toad. I had to manually grant `root`@`%` privileges in mysql in order for that to work. Can I chnage the chef.json to do that automatically?

Reply

I'm not sure if you can do that with the typical json. The database recipe should let you do that, but you'll likely need to write some calls to it instead of defining json. https://github.com/opscode-...

Reply

If this is your first time setting up rails with vagrant or you don't have any rails app, you need to installl rail gem 'gem install rails' and make rails executable 'rbenv rehash' before run 'rails server'. to check your rails is installed, run 'rails -v'

Reply
Gruff Davies Gruff Davies

One gotcha worth pointing out here that I got stung by: there's a bug in the current upgrade of Vagrant. Apparently several: https://www.vagrantup.com/b.... So if you're already using vagrant, it's best to uninstall it and install fresh which fixed things for me. I also upgraded VirtualBox but this was straightforward.

Reply
Camilo Rivera Camilo Rivera

Hi,

FYI, I was getting the following error this morning:

NoMethodError: mysql_service[default] (mysql::server line 20) had an error: NoMethodError: undefined method `sensitive' for Chef::Resource::Execute

Apparently, this bug was introduced with the latest version of the mysql cookbook (v5.5.4 as of today).

If this ever happens to anyone, you can just specify the previous version in the Cheffile as follows:

cookbook 'apt'
cookbook 'build-essential'
cookbook 'mysql', '5.5.3'
...
cookbook 'vim'

After this, I just entered the vagrant provision command and everything worked like a charm.

Cheers.

Reply

Awesome find! Thanks for sharing this.

Reply

Thanks, I just ran into this today!

Reply
Bishisht  Bhatta Bishisht Bhatta

This
vagrant plugin install vagrant-librarian-chef

fails on my machine. I have posted full details on stackoverflow(http://stackoverflow.com/qu...

hope to get some solution from you guys.

Reply
Anthony Candaele Anthony Candaele

I have a question about this line in the Vagrantfile:

mysql: {
server_root_password: ''
}

does this mean that this setup doesn't work with Postgres?

greetings,

Anthony

Reply

You'll have to swap the MySQL instructions with Postgres ones. This tells Chef how to setup a MySQL server inside the Vagrant box, so you'll need to do the same for Postgres. I'm not sure of all the differences off the top of my head but a quick google search for postgres + chef should find you exactly whaty ou need.

Reply
Anthony Candaele Anthony Candaele

I followed the instructions in this tutorial and everything ran successfully. Then I ran the 'vagrant up' and 'vagrant ssh' command. However, I don't seem to have a /vagrant directory. I have a .vagrant directory with in it a 'machines' directory.
Am I missing something?

Reply
Anthony Candaele Anthony Candaele

oops, seems I can cd into '/vagrant', it's all good.

Reply
Anthony Candaele Anthony Candaele

I just ran into an issue with Launchy, which won't open a page in the browser, when on a virtual machine:

Failure/Error: save_and_open_page
Launchy::CommandNotFoundError:
Unable to find a browser command. If this is unexpected, Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at https://github.com/copiousf...

not being able open a page in the browser when testing with Capybara is kind of a show stopper for me : (

Reply

You might check this out http://spin.atomicobject.co...

Reply
Kartik Danidhariya Kartik Danidhariya

my os is ubuntu 12.04 64 bit
i am successfully install Vagrant
After when i try to install virtual box using this
sudo dpkg -i virtualbox-4.3_4.3.20-96996~Ubuntu~precise_i386.deb
it gives following error

Selecting previously unselected package virtualbox-4.3:i386.
(Reading database ... 185893 files and directories currently installed.)
Unpacking virtualbox-4.3:i386 (from virtualbox-4.3_4.3.20-96996~Ubuntu~precise_i386.deb) ...
dpkg: dependency problems prevent configuration of virtualbox-4.3:i386:
virtualbox-4.3:i386 depends on libdevmapper1.02.1 (>= 2:1.02.20).
virtualbox-4.3:i386 depends on libpython2.7 (>= 2.7).
virtualbox-4.3:i386 depends on libvpx1 (>= 1.0.0).
virtualbox-4.3:i386 depends on psmisc.
dpkg: error processing virtualbox-4.3:i386 (--install):
dependency problems - leaving unconfigured
Processing triggers for ureadahead ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for shared-mime-info ...
Processing triggers for desktop-file-utils ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf.index...
Processing triggers for gnome-menus ...
Errors were encountered while processing:
virtualbox-4.3:i386

how can i solve ,thanks in advance!!!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.