Using Vagrant for Rails Development

A tutorial for using Vagrant in your Rails development environment on Mac, Linux, and Windows



Overview

This will take about 20 minutes.

Vagrant is a tool to automatically setup a development environment inside a virtual machine on your computer. This means your development environment can exactly match the production server and your coworkers can all run exactly the same software.

Your Rails development environment will stay the same no matter what your development computer setup is like. Plus, when you need to revisit a project 12 months later, you can get up and running within minutes. Future you will thank you for setting it up at the beginning of your project.

We're also going to use Chef which helps us automate how our virtual machine development environment gets setup. It will take care of setting up Ruby and all the other packages on our system. It's pretty rad.

Enough of a sales pitch, let's get to it.

Setting Up Vagrant

Make sure you have 1GB or 2GB of free RAM on your computer before proceeding because Vagrant runs a full operating system inside a virtual machine to run your Rails applications.

The first step is to install Vagrant and VirtualBox on your computer.

  1. Install Vagrant
  2. Install VirtualBox

VirtualBox is where your virtual machines will run. They will be headless which means that they will run in the background and you will interact with them over SSH.

Next we're going to install two plugins for Vagrant.

  • vagrant-vbguest automatically installs the host's VirtualBox Guest Additions on the guest system.
  • vagrant-librarian-chef let's us automatically run chef when we fire up our machine.
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-librarian-chef-nochef

This can take a while.

Create the Vagrant config

First off, hop into a Rails project that you want to setup Chef for and run the following commands.

cd MY_RAILS_PROJECT # Change this to your Rails project directory
vagrant init
touch Cheffile

This will create both the Vagrantfile and Cheffile for us to customize.

Your Cheffile

Now we're going to setup our Cheffile. This file is just like your Rails Gemfile but for Chef. This file defines the Chef cookbooks that we will use in our project. Later on in the Vagrantfile we will tell Vagrant how to use these cookbooks to setup our environment.

We just want to paste the following code into our Cheffile:

site "http://community.opscode.com/api/v1"

cookbook 'apt'
cookbook 'build-essential'
cookbook 'system'
cookbook 'ruby_build'
cookbook 'ruby_rbenv', '~> 1.1.0'
cookbook 'postgresql', git: 'https://github.com/ChowOps/chef-postgresql'
cookbook 'vim'

Your Vagrantfile

Our Vagrantfile defines the operating system and Chef configuration for our virtual machine.

We're going to be using Ubuntu 16.04 xenial 64-bit (change to "xenial32" if you need to use 32-bit) with 2GB of memory. It is also going to forward port 3000 from the virtual machine to our computer so when we run rails server we can access the server inside the virtual machine from our regular browser. Last but not least, we have Chef setup Ruby 2.2.1 and MySQL inside our VM.

You can replace the Vagrantfile contents with the following:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"
REQUIRED_PLUGINS        = %w(vagrant-vbguest vagrant-librarian-chef-nochef)

plugins_to_install = REQUIRED_PLUGINS.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
  puts "Installing required plugins: #{plugins_to_install.join(' ')}"
  if system "vagrant plugin install #{plugins_to_install.join(' ')}"
    exec "vagrant #{ARGV.join(' ')}"
  else
    abort "Installation of one or more plugins has failed. Aborting. Please read the Bike Index README."
  end
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/xenial64"

  # Configure the virtual machine to use 1.5GB of RAM
  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "1536"]
  end

  # Forward the Rails server default port to the host
  config.vm.network :forwarded_port, guest: 3000, host: 3000

  # Use Chef Solo to provision our virtual machine
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["cookbooks", "site-cookbooks"]

    chef.add_recipe "apt"
    chef.add_recipe "build-essential"
    chef.add_recipe "system::install_packages"
    chef.add_recipe "ruby_build"
    chef.add_recipe "ruby_rbenv::user"
    chef.add_recipe "ruby_rbenv::user_install"
    chef.add_recipe "vim"
    chef.add_recipe "postgresql::server"
    chef.add_recipe "postgresql::client"

    chef.json = {
      rbenv: {
        user_installs: [{
          user: 'ubuntu',
          rubies: ["2.4.0"],
          global: "2.4.0",
          gems: {
          "2.4.0" => [{ name: "bundler" }]
        }
        }]
      },
      system: {
        packages: {
          install: ["redis-server", "nodejs", "libpq-dev"]
        }
      },
      postgresql: {
        :pg_hba => [{
          :comment => "# Add vagrant role",
          :type => 'local', :db => 'all', :user => 'ubuntu', :addr => nil, :method => 'trust'
        }],
        :users => [{
          "username": "ubuntu",
          "password": "",
          "superuser": true,
          "replication": false,
          "createdb": true,
          "createrole": false,
          "inherit": false,
          "login": true
        }]
      }
    }
  end
end

Running Vagrant

Now that we've got Vagrant and Chef configured properly, we'll start up the Vagrant virtual machine and ssh into it.

# The commented lines are the output you should see when you run these commands

vagrant up
#==> default: Checking if box 'ubuntu/xenial64' is up to date...
#==> default: Clearing any previously set forwarded ports...
#==> default: Installing Chef cookbooks with Librarian-Chef...
#==> default: The cookbook path '/Users/chris/code/test_app/site-cookbooks' doesn't exist. Ignoring...
#==> default: Clearing any previously set network interfaces...
#==> default: Preparing network interfaces based on configuration...
#    default: Adapter 1: nat
#==> default: Forwarding ports...
#    default: 3000 => 3000 (adapter 1)
#    default: 22 => 2222 (adapter 1)
#==> default: Running 'pre-boot' VM customizations...
#==> default: Booting VM...
#==> default: Waiting for machine to boot. This may take a few minutes...
#    default: SSH address: 127.0.0.1:2222
#    default: SSH username: vagrant
#    default: SSH auth method: private key
#    default: Warning: Connection timeout. Retrying...
#==> default: Machine booted and ready!
#==> default: Checking for guest additions in VM...
#==> default: Mounting shared folders...
#    default: /vagrant => /Users/chris/code/test_app
#   default: /tmp/vagrant-chef-1/chef-solo-1/cookbooks => /Users/chris/code/test_app/cookbooks
#==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it

vagrant ssh
#Welcome to Ubuntu 16.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
#
# * Documentation:  https://help.ubuntu.com/
#
# System information disabled due to load higher than 1.0
#
#  Get cloud support with Ubuntu Advantage Cloud Guest:
#    http://www.ubuntu.com/business/services/cloud
#
#
#[email protected]:~$

The first time you run vagrant up will take a while because it will provision your virtual machine with the chef configuration. After the first time, vagrant up won't have to run Chef and it will boot much faster.

If you ever edit your Vagrantfile or Cheffile, you can use the following command to reconfigure the machine.

vagrant provision

Using Rails inside Vagrant

Vagrant sets up the /vagrant folder as a shared directory between the virtual machine and your host operating system. If you cd /vagrant and run ls you will see all the files from your Rails application.

bundle to install all your gems inside the virtual machine.

rbenv rehash to make sure the executables from the gems we just installed (like rails) are available.

rake db:create && rake db:migrate to create and migrate your database.

rails server from this directory will run your Rails application on port 3000. You will still be able to access Rails just like usual on localhost:3000.

Conclusion

Vagrant is an awesome tool for making a portable development environment that lives with your code. With a pretty simple configuration using Chef, we can be up and running in absolutely no time.

If you need to setup your Vagrant machine again or one of your coworkers needs to get setup, all you have to do is run vagrant up to have your entire virtual machine ready to go.



Discussion


Gravatar
Kostas on

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.

Gravatar
Chris Oliver (170,390 XP) on

Thanks! I'll be sure to update that.


Gravatar
Carlo DiCelico on

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!

Gravatar
Chris Oliver (170,390 XP) on

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


Gravatar
Cam on

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

Gravatar
Chris Oliver (170,390 XP) on

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.

Gravatar
Cam on

I tried setting http_proxy & https_proxy in the vagrant users .bashrc and even in /etc/environment, no luck. Then I discovered Ubuntu will blat any env vars when executing any command under sudo (EG: sudo apt-get update). That can be stopped by editing /etc/sudoers.

See: http://memset.wordpress.com...

Still no luck, eventually I stumbled across this fantastic vagrant plugin:
See: https://github.com/tmatilai...

That works perfectly, in my vagrant file I use the host's http_proxy & https_proxy environment variables (if present) when calling this plugin inside the Vagrantfile. No messy passwords or settings needing to be stored in the Vagrantfile. Nice.

One minor issue I am having now is timeout. When I run this on my home network which is not so fast, most things work, but it can be hit and miss, depending on network performance. Any idea where that can be overridden with chef solo?


Gravatar
Joel Taylor on

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

Gravatar
Chris Oliver (170,390 XP) on

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

Gravatar
Joel Taylor on

That makes perfect sense - thanks!

Gravatar
Gruff Davies on

I'm stuck at starting rails server. I get the same message as Dave upthread (The program 'rails' can be found in the following packages etc.) but no idea how to proceed. His solution didn't fix anything for me. I read you comment about bundler, so I tried " sudo gem install bundler" and then "sudo gem install bundler" which seemed to be working but broke trying to install bcrypt. I'm not even sure I should have been going this route?

Gravatar
Chris Oliver (170,390 XP) on

If you used rbenv and have installed the Rails gem, make sure to run

rbenv rehash

This will make the "rails" executable visible to your terminal by putting a stub in your PATH.

Gravatar
Gruff Davies on

Thanks. I hadn't installed the rails gem. I assumed that would be done by this. Trying that now after a fresh start. EDIT: Actually, I just realised, all I had to do was run 'bundle' once the VM was up and I was in my project directory. Bundle didn't exist last time I did any rails dev years ago so I handle understood your comment about being able to use it. Everything makes sense now. THANKS!

Gravatar
Chris Oliver (170,390 XP) on

Yep! :) Glad you got it working!


Gravatar
Guest on

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

Gravatar
Chris Oliver (170,390 XP) on

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...

Gravatar
Pablo Crivella (10 XP) on

Same error here, did you manage to solve it?

Gravatar
Anthony Candaele on

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.

Gravatar
Anthony Candaele on

I should have been patient, it's ok now :)


Gravatar
Dana Nourie (930 XP) on

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?

Gravatar
Chris Oliver (170,390 XP) on

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.

Gravatar
Roderick Silva (30 XP) on

Any resources on setting up one Vagrant/Rails box to learn and work with multiple projects?

Gravatar
Chris Oliver (170,390 XP) on

The goal is really to use a separate Vagrant box for each project. The reason for that is that each time you can be sure you have everything separated out nicely and you can trust that you don't have some accidental dependencies you forgot about it or weren't aware of.

Gravatar
Roderick Silva (30 XP) on

Yes, I totally understand the need (especially in a team environment). Forgive me for not understanding the vagrant part (newb) but this sounds like I'd be downloading and storing a version of Ubuntu for each project.

My only experience with Vagrant is with Laravel's Homestead box where I have multiple projects within my Code directory. Composer then pulls down the packages/gems for each project.

Gravatar
Chris Oliver (170,390 XP) on

That's a good question. I think it downloads the primary image once and clones it for each project. You should be able to run "ls -la" to determine the directory size and see just how much it's taking up. I'd guess it's a couple GB for each project.

For personal projects, Vagrant isn't really necessary so I wouldn't really say you need it for that. Mostly just like team environments like you mentioned.

I'd guess there is a way of sharing the Vagrant VM, but I'm not sure off the top of my head.


Gravatar
Beau on

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.


Gravatar
Frey (310 XP) on

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...

Gravatar
Chris Oliver (170,390 XP) on

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


Gravatar
hookswp on

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

Gravatar
Chris Oliver (170,390 XP) on

Most definitely!

Gravatar
leonard bogdonoff (10 XP) on

What was your schedule for the docker tutorial?

Gravatar
Brendan Vinson on

Really interested in the docker tutorial as well.


Gravatar
jesterfraud on

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.


Gravatar
Dave Kaplan on

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

[email protected]:/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!

Gravatar
Chris Oliver (170,390 XP) on

Thanks for the tips Dave! :)

Gravatar
Joel Collins on

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

Gravatar
Kartik Danidhariya on

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!!!

Gravatar
Daniil Garmoshka Kucherenko on

# After vagrant installed & provisioned, run inside vm:

cd /vagrant

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

Gravatar
Samar Singh on

Do I need to do something else If I am using Puma ? I followed the procedure first got the error "

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

Then I did

gem install bundlergem install rails -v 4.2.1
rbenv rehash
bundle

Now I am getting the following Error :
#############
=> Booting Puma

=> Rails 4.2.4 application starting in development on http://localhost:3000

=> Run `rails server -h` for more startup options

=> Ctrl-C to shutdown server

Exiting

/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/less-rails-2.7.0/lib/less/rails/railtie.rb:19:in `block in <class:railtie>': undefined method `register_preprocessor' for nil:NilClass (NoMethodError)

from /home/vagrant/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'

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

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.


Gravatar
Gruff Davies on

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?

Gravatar
Chris Oliver (170,390 XP) on

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-...

Gravatar
Gruff Davies on

Thanks Chris. I decided it wasn't good practice in the end and instead I'm using putty with a tunnel to ssh into my VM, just as I would in production. I think it's better to keep the environments as close as possible. And this method is much less painful to set up and it's more secure.

Gravatar
Chris Oliver (170,390 XP) on

Cool, it's always good to have consistency like that between development and production so I'm definitely with you there.


Gravatar
Salahuddin Hairai (10 XP) on

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'


Gravatar
Gruff Davies on

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.


Gravatar
Camilo Rivera on

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.

Gravatar
Chris Oliver (170,390 XP) on

Awesome find! Thanks for sharing this.

Gravatar
John Nadeau on

Thanks, I just ran into this today!


Gravatar
Bishisht Bhatta on

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.


Gravatar
Anthony Candaele on

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

Gravatar
Chris Oliver (170,390 XP) on

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.

Gravatar
Anthony Candaele on

thanks Chris, I'll give Vagrant a go on my next Rails project.

Gravatar
Anthony Candaele on

in my Vagrantfile, I changed the lines:

chef.add_recipe "mysql::server"
chef.add_recipe "mysql::client"

to

chef.add_recipe "postgresql::server"
chef.add_recipe "postgresql::client"

then I changed the line:

mysql: {
server_root_password: ''
}

to:

postgresql: {
:version => "9.3",
:password => {
:postgres => "foo"
}
}

and long and behold, it works!


Gravatar
Anthony Candaele on

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?

Gravatar
Anthony Candaele on

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

Gravatar
Chris Oliver (170,390 XP) on

Yeah, /vagrant is inside the VM, not on your local machine.


Gravatar
Anthony Candaele on

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 : (

Gravatar
Chris Oliver (170,390 XP) on

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


Gravatar
Kartik Danidhariya on

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!!!


Gravatar
Kartik Danidhariya on

when i give vagrant up it sows following error

==> default: Recipe Compile Error
==> default: ================================================================================
==> default:
==> default: Chef::Exceptions::RecipeNotFound
==> default: --------------------------------
==> default: could not find recipe server for cookbook mysql
==> default:
==> default: [2014-12-24T12:22:59+00:00] ERROR: Running exception handlers
==> default: [2014-12-24T12:22:59+00:00] ERROR: Exception handlers complete
==> default: [2014-12-24T12:22:59+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2014-12-24T12:22:59+00:00] ERROR: could not find recipe server for cookbook mysql
==> default: [2014-12-24T12:23:00+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Pls help i am new for ROR and vagrant,
Thanks in advance!!!

Gravatar
Woojin Joe (10 XP) on

I got a same errors like above error messages, but i can't find the solution.

Did you find a way to solve it?

Gravatar
semicircle21 on

I got this too, and fixed with this:
change the mysql line in Cheffile:

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

...


Gravatar
semicircle21 on

..just in case someone, run into this error:

undefined method `rbenv_rehash' for #<chef::provider:package:rbenvrubygems:0x000000049c8340>

Here's the solution:
Change the 'rbenv' line in the Cheffile:

`
cookbook 'rbenv', git: 'https://github.com/RayMangu...
`

Explanation:

I'm new to rails too, and I thought it's a rbenv / chef related problem,

then I found this in Github:

https://github.com/RayMangu...

It seems the chef-rbenv is out of date. And, the newest fork is the RayMangum's one.


Gravatar
Jingqiang Zhang (10 XP) on

This is a good guide:-) But after I run `vagrant up`, I got these errors:

➜ MY_RAILS_PROJECT vagrant up
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.5/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Installing Chef cookbooks with Librarian-Chef...
[default] Destroying VM and associated drives...
[default] Running cleanup tasks for 'chef_solo' provisioner...
/Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `block in connect'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/timeout.rb100in `timeout'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
from /Applications/Vagrant/embedded/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/jingqiangzhang/.vagrant.d/gems/gems/librarian-chef-0.0.4/lib/librarian/chef/source/site.rb:353:in `block in http_get'

My ruby version is:

➜ MY_RAILS_PROJECT ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

Gravatar
Chris Bloom on

You may want to try setting `config.ssh.forward_agent = true` in your Vagrantfile. I was unable to checkout anything from github via bundler without that. It may be related to the error you're seeing.

Gravatar
Guogengrui on

I am sad to get the same error. could you tell me how to solve it . ths!


Gravatar
Mark Henke (10 XP) on

...except Vagrant-librarian-chef doesn't work on Windows 7 (at least it didn't work for me) causing me to have to look elsewhere to get Rails up and running

Gravatar
sayth on

vagrant-librarian-chef-nochef


Gravatar
Chris Bloom on

I am getting to the point with the number of apps that I work on and the diversity of environments that I need to maintain that Brew and RVM alone no longer cut it. I was hoping that the combination of Vagrant, VirtualBox, Librarian, and Chef would be the answer, but I've been struggling with these steps over the last week to setup VMs for two different projects and I'm about ready to give up and look elsewhere.

The main issue is that I keep running into conflicts/errors in the Chef recipes. It took me the better part of 3 days to successfully provision a VM using this method with Postgres 8 and PostGIS 1.5. Granted those are both deprecated versions , but that's what I needed for one particular project that we maintain. You state towards the end of the article that I should be able to just run `vagrant provision` if I change the Vagrantfile or the Cheffile and it will reprovision the box, but it's been my experience that once I run `vagrant up` the Chef recipes won't run again until I destroy the VM and start over. If I try to reprovision it just tells me that the server is already setup and Chef never runs again. Since each fresh start takes anywhere from 45 minutes to an hour and a half, that all adds up when I have to keep starting over every time there's a new error.

In my last attempt I ran into a bug with Ubuntu 14 and Chef 12 (https://github.com/opscode/... that took me a while to figure out. Since there's no way (that I've found) to specify what version of Chef gets installed on the VM during provisioning, the only way around it was to downgrade to Ubuntu 12 instead.

And now I'm stuck trying to get the default MySQL recipe to run but it keeps telling me "You must supply a name when declaring a package resource", and I see no way to do that in the instructions for the MySQL cookbook.

I've never had much luck with Chef in general. I generally just need to setup very simple servers, and Chef seems like too much overhead for that task. The alternative of setting things up manually is just as tedious though, so I'm at a crossroads.

Gravatar
Chris Bloom on

I should have RTFM as far as specifying a version of Chef to install on the server: https://docs.vagrantup.com/...

Gravatar
Chris Bloom on

In case anyone else runs into the issues I kept running into:

Chef doesn't run again on `vagrant provision` if you install RVM. See https://github.com/opscode/... and https://github.com/opscode/... for possible fixes, or don't use RVM. If you do use RVM, you'll also need to figure out a way to get around the issue with RVM updates and PGP keys in subsequent provisioning runs, detailed at https://github.com/fnichol/....

For my MySQL problem, I had to code dive into the mysql recipe files to discover that the mysql cookbook is not configured to install the version of MySQL I needed on the version of Ubuntu I was using, so I had to downgrade Ubuntu yet again to 10.04. Frustrating that they wouldn't provide a table of supported installs.


Gravatar
Brandon on

It looks like nodejs-cookbook is deprecated, here's what the readme says:
Important notice: this repository has been deprecated and the development of the nodejs cookbook has been moved here: https://github.com/redguide...


Gravatar
halt on

If you do not need chef, this will work in 5 minutes ;)
https://github.com/rails/ra...
and it is, unlike this tutorial, up-to-date!

Gravatar
Chris Oliver (170,390 XP) on

Thanks for sharing!

Gravatar
Paul on

This is not for rails development, it's for developing rails itself.


Gravatar
Jon Thomas on

I also had to specify a version for mysql, but after I did that it worked perfect.


Gravatar
Jon Thomas on

When I use vagrant up, it puts me in the user directory "~", and I can run ruby -v and get the correct output. However, when I cd to /vagrant, and run ruby -v it says "rbenv: version `ruby-1.9.3-p551' is not installed". Why can't I use the ruby command outside of the user directory with this setup?


Gravatar
Mao82 on

Finally a working cookbook for rbenv:

cookbook 'rbenv', git: 'https://github.com/john-tel...


Gravatar
Mao82 on

Finally a working cookbook for rbenv:
cookbook 'rbenv', git: 'https://github.com/john-tel...


Gravatar
Łukasz Antkowiak on

why such tutorials always ends when the most important part begins? Am I supposed to install my dev tools on guest (it may not be full blown ide, I think that configured vim still counts), or still use it on my host? If tools still should be on host, how did you debug your app?

Gravatar
Chris Oliver (170,390 XP) on

There is basically no difference in your workflow other than SSHing in for running the server. Like I mentioned, the folder is shared between the host and the VM guest. You have to install all the tools inside the VM to run the app, but since it's shared you can edit in either place. You debug your app exactly like normal through the terminal. It just happens to be inside SSH to the VM, but there is almost no difference.


Gravatar
Siddhartha Majji on

Hello there! after installing the bundler, I'm getting an error message that
"Bundler::GemfileNotFound"
thanks in advance!


Gravatar
Ryan Carter on

Chris, great tutorial. Thanks. Got me up and running quick. Question for you though. If I wanted to add java, git, nginx, and others, I would include their cookbook in Cheffile, then config in vagrantfile, correct?

Gravatar
Chris Oliver (170,390 XP) on

Yeah that should do it. You can sometimes use the apt packages for those or if you want to customize the install (like get the latest version) then cookbooks usually make the most sense.


Gravatar
Christopher Yeung (70 XP) on

So do I have to run virtualbox and vagrant in production server as well?

Gravatar
Chris Oliver (170,390 XP) on

Nope, this is mainly just to emulate production on your development machine.


Gravatar
Angie on

Hi, everything works great except for bundler is not getting installed when the vm is provisioned. I navigate to my directory and then run bundle install and get this message:

The program 'bundle' is currently not installed. To run 'bundle' please ask your administrator to install the package 'bundler'

I modified the following from the Vagrantfile listed in this tutorial to use ruby 2.1.3 and added docker to pull and run redis:

# Install Ruby 2.1.3 and Bundler

# Set an empty root password for MySQL to make things simple

chef.json = {

rbenv: {

user_installs: [{

user: 'vagrant',

rubies: ["2.1.3"],

global: "2.1.3",

gems: {

"2.1.3" => [

{ name: "bundler" }

]

}

}]

},

mysql: {

server_root_password: ''

}

}

end

config.vm.provision "docker" do |d|

d.pull_images "redis"

d.run "redis"

end

end

-------------

Does anyone know why bundler isn't being installed and how to configure the vagrant file so that it does get installed? I've already tried rbenv rehash before running bundle install, and get the same "bundler not installed" message. This isn't the biggest issue, because I can run gem install bundler, but I'm attempting to automate the deployment process of our ruby dev environments as much as possible.. so finding the solution would be great!

Any help appreciated, thanks!

Gravatar
Chris Oliver (170,390 XP) on

I ran into the same problem recently. Couldn't figure out what was wrong but maybe the gem had updated and it no longer recognized the option. You can install it manually and things work fine. Would love if someone finds a good solution for this.

Gravatar
Rob on

Any progress with this? I am new to Vagrant and am just trying to provision a solid, reusable setup for multiple developers and I am just completely stuck on this. I'm not sure how to write the script to install bundler manually. Which gem was updated??

Gravatar
Chris Oliver (170,390 XP) on

I haven't had the time to find any solution to that recently. Hopefully someone can leave a comment if they find a solution!

Gravatar
David Darke on

Yeah have the same problem with this :( would love a solution!

Gravatar
Rustan Corpuz (20 XP) on

how to install it manually?

Gravatar
Enrique Benitez (300 XP) on

gem install bundler

Gravatar
baconinja on

I was getting this error no matter what ... "The program bundle is not currently installed". However, here is the combination that fixed it for me.
1. Locate the version of Bundler used in project I wanted to Vagrant
2. Downgraded Vagrant to match the version
3. Run rbenv rehash AFTER the bundler install
4. Bundle project and make money


Gravatar
Mincă Daniel Andrei on

Mine loops through "Connection timeout...Retrying..."


Gravatar
Rovin Varshney on

Thanks. Really helpful vagrant tutorial


Gravatar
ukritdane on

Thanks for sharing this information. I have not come across this issue while working on Rail development. But i hope this blog will help the one who are looking for this information.I have bookmarked this Blog.


Gravatar
Ocean on

everytime I try to run bundle, it says "Could not locate Gemfile or .bundle/ directory"
I've already made sure bundler was installed and rails 4.2, since i know some people were having problems with that, any idea whats wrong?

Gravatar
Ocean on

nvm got it fixed, but still can't access the forwarded port

Gravatar
Carlton Smith III on

How did you fix it?

Gravatar
Ocean on

I ended up just using a vagrant box that was already set up, sorry I can't help more.


Gravatar
Runy Calmera on

I'm getting this information when I put in the first comment. Is this still the way to use Vagrant with Ruby on Rails development?

:

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...

Gravatar
Chris Oliver (170,390 XP) on

Sounds like you installed the vagrant rubygem before. You'll want to uninstall that and download it from vagrant's website instead.


Gravatar
Sebastian (1,560 XP) on

Hi,

um just to be clear, the _code/landingpage_ folder is empty...?!


Gravatar
Jay Killeen (1,580 XP) on

It is weird. When I ssh inti vagrant and run pwd I see `/home/vagrant` but when I run ls I don't see any files.If I run `ls /vagrant' I see all my files though that are being synced.

This boggled my mind for at least 4 or 5 hours.

If I `cd /vagrant` and `ls` I'll see all my files. But if I run `pwd` from there I am in `/vagrant`.

Is anyone else confused why vagrant would create a folder in my home folder `/home/vagrant` but actually sync with `/home`??

So happy now that I have figured this out!!! :D


Gravatar
Carlton Smith III on

Do I need to have rails set up on my main machine also for this to work? Everything seems fine until I run 'bundle' and it says, "The program 'bundle' is currently not installed..." - I see that someone else has this issue as well, but I don't see a workable solution. I'm just wondering if this is happening because I don't have rails installed on my windows machine. I was hoping I could avoid doing that for this solution.

Gravatar
Carlton Smith III on

I found the problem. I had installed the vagrant plugins on a previous attempt and didn't realize I needed to do it again. After installing the plugins again and provisioning everything worked as it should.


Gravatar
Gino on

Excuse me, why yesterday with "bin/rails s" with webrick (and also Puma) I can open the localhost:3000 and today (with nothing changed) I can't and have to start with "bin/rails s -b 0.0.0.0" ???

Gravatar
Gino on

Anyone?


Gravatar
Runy Calmera on

Hi thanks for the tutorial. I can't get bundle installed. I get this: Could not locate Gemfile or .bundle/ directory

Have anymore gotten this problem?

Runy


Gravatar
Runy Calmera on

What I don't understand is this. If I'm making an app called testapp and then also work on another app called testapp2. Do I need to go in the /vagrant directory and then put there rails new testapp and rails new testapp2? So do these rails apps go IN the vagrant folder?

My set up is as follows:

I created a folder called railsprojects
I did vagrant init from within this folder railsprojects.

I had NO rails apps installed in this folder.

So I went to this folder railsprojects
Then I did vagrant up
And then vagrant ssh.

And now I want to start creating rails apps. I have many rails apps to create and they all use the same virtual machine.

In which folder should I run the rails new testapp comment?

Many thanks.

Runy


Gravatar
German Mendoza on

Where is my synced folder, I have created a project in vagrant, but I can not find in my local system, somebody help me please!!!.

Gravatar
Chris Oliver (170,390 XP) on

It's /vagrant


Gravatar
German Mendoza on

Thanks for information.

But I want create in my local host a url as

http://api.test.com

how can I do this?


Gravatar
Aruj Parajuli (60 XP) on

I m getting error like these. May be i miss something?

The box you're attempting to add doesn't support the provider
you requested. Please find an alternate box or use an alternate
provider. Double-check your requested provider to verify you didn't
simply misspell it.

If you're adding a box from HashiCorp's Atlas, make sure the box is
released.

Name: ubuntu/trusty64
Address: https://atlas.hashicorp.com...
Requested provider: ["vmware_desktop", "vmware_fusion", "vmware_workstation"]


Gravatar
Joseph An on

Awesome tutorial!
Do the other developers on the same team who don't have Vagrant yet have to install plugins as well?


Gravatar
John Roberson on

Can someone please clarify what the Vagrantfile should look like if you wanted rails to be installed automatically on vagrant up? :-) Thanks for the tutorial btw! I've got it up and running. I just want to be able to automate it further for future use and still have a bit to learn about Chef and Vagrant.


Gravatar
C Lokesh Reddy on

I followed the whole post and successfully configured everything. But when I've restarted the system and opened vagrant linux terminal in the folder and run following command 'cd /vagrant' & 'ls', I'm not able to see the files in the directory. It happened to me 3 times and every time I had to do all the process again copying all my progect files into other folder and all commands of vagrant, all updates of ubuntu and rails again every time. Someody please help why is the link between vagrant getting vanished once the system is restarted?


Gravatar
Fritz Rodriguez Jr. on

Hey Chris! As always my man! Thanks for another great screencast. After going through the tutorial notes, I couldn't get the server up and running. Then I checked out the video and you mentioned using 'rails server -b 0.0.0.0' to start the rails server and it worked. Might want to include that in the documentation

Also, there is another resource I found that might be helpful... https://railsbox.io/

Take care and thanks again...Best!


Gravatar
Intruder7s on

Thanks for your guide! I am kinda stuck though!

1. Right after the installation of Vagrant and then VB, what is the next step? I just opened a cmd and went from there. Didn't know what else to do.

2. Since I am in Windows 7 x64 I am getting the "'touch' is not recognized as an internal or external command, operable program or batch file." message. Any workarounds ?

Thanks

Edit for anyone wondering.

1. I am using Cygwin with some extra plugins to implement commands like top, diff and a few others. It is the best option when working in Windows and want to do simple stuff.

2. Using Cygwin I can use the touch command.
However since "touch" is not availiable in windows, this tutorial should instuct the user to use this command. So if you are having trouble in this step of the tutorial, when instructed to "touch Cheffile" simply create a file at the specific folder you are working on and name it Cheffile.


Gravatar
Łukasz Siwiński on

Thanks for this tutorial Chris. Works fine for me, but I've encountered 1 problem during `vagrant up` on my Windows 10 x64 Box:

%userprofile%/.vagrant.d/gems/gems/vagrant-vbguest-0.11.0/lib/vagrant-vbguest/download.rb:23:in `unlink': Permission denied @ unlink_internal - %userprofile%/.vagrant.d/tmp/VBoxGuestAdditions_5.0.10.iso (Errno::EACCES)

This post on stackoverflow help me to solve it http://stackoverflow.com/qu...

But I think that's just a "workaround" of some real problem that was reported here: https://github.com/refile/r... and here: https://openedx.atlassian.n... too.


Gravatar
Jay Killeen (1,580 XP) on

I am getting the error "ERROR: You must specify at least one cookbook repo path". Will come back if I figure it out. The only changes I have made to Chris' code is making it Postgres instead of MySQL.

Gravatar
Jay Killeen (1,580 XP) on

I hadn't run the line `vagrant plugin install vagrant-librarian-chef-nochef`. I have done that although now Chef installation takes so long I stopped it. 1hr + so I don't think that classifies for 'This can take a while.`


Gravatar
superiorpaper on

This might really become useful and really helpful for them to have especially that people might need to know on how are they going to use some certain kind of tools that will surely guide them with their work or will going to help them in promoting something for their work.


Gravatar
Jorge Anzola on

I'm getting this error after "vagrant up"

from C:/Users/JorgeAnzola/.vagrant.d/gems/gems/librarian-chef-nochef-0.2.0/lib/librarian/chef/source/site.rb:354:in `block in http_get'

folloewd by a bunch of code lines. Does any one knows how to solve it?


Gravatar
Rahmat Awalludin on

when "vagrant plugin install vagrant-librarian-chef-nochef", i get error "Could not find gem 'vagrant-librarian-chef-nochefvagrant (>= 0) ruby' in any of the gem sources listed in your Gemfile or available on this machine."


Gravatar
Ryan R Wilkins on

Even after I assign 0.0.0.0 I am still unable to get my localhost to work on chrome.

"This site can’t be reached

localhost refused to connect.
"


Gravatar
allenak on

Make sure you use

chef.channel = "stable"

So you don't accidentally get an unstable build that doesn't work with your vagrant setup.


Gravatar
Dave on

Following these instructions I've been hit with this error:

[2016-06-22T22:33:38+00:00] INFO: HTTP Request Returned 404 Not Found: Parent not found: chefzero://localhost:8889/nodes

The server returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.

chef_server_url "chefzero://localhost:8889"

I'm very new to all this and not sure what would need changed to fix it?!

Any help/hand holding would be great!

Gravatar
Alex Bezek on

I struggled with this for a while, finding multiple stack overflow and github issues saying to specify a version of specify the channel to be stable. Finally figured out I had missed this step. Hope it helps someone
vagrant plugin install vagrant-librarian-chef-nochef

Gravatar
Jim Rowe on

Lifesaver! Thanks.


Gravatar
Kilian Sprotte (140 XP) on

How to change the Vagrantfile to install Ruby 2.3.1, which is not downloadable as a binary?

Gravatar
Chris Oliver (170,390 XP) on

Since we're using rbenv, it should compile Ruby instead of downloading it as a binary. You should be able to change the version numbers, although I haven't tried it with 2.3.1 yet.

Gravatar
Kilian Sprotte (140 XP) on

Unfortunately, I don't know how to tell it to go for compiling. It fails when not being able to download. :(
As I want to use Rails 5, I need this more recent Ruby version.

Gravatar
Chris Oliver (170,390 XP) on

What's the error you're getting?

Gravatar
Kilian Sprotte (140 XP) on

==> default: [2016-09-20T21:56:22+00:00] ERROR: rbenv_ruby[2.3.1 (vagrant)] (vagrant) (rbenv::user line 45) had an error: Mixlib::ShellOut::ShellCommandFailed: rbenv_script[rbenv download 2.3.1 (vagrant)] (/var/chef/cache/cookbooks/rbenv/providers/ruby.rb line 81) had an error: Mixlib::ShellOut::ShellCommandFailed: script[rbenv download 2.3.1 (vagrant)] (/var/chef/cache/cookbooks/rbenv/providers/script.rb line 38) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
==> default: ---- Begin output of "bash" "/tmp/chef-script20160920-6143-1sxflk7" ----
==> default: STDOUT: Download and extract ruby 2.3.1 from the RVM repository
==> default: STDERR: https://rvm.io/binaries/ubu... cannot be reached
==> default: Cannot find a built version of '2.3.1' compiled for your current system: Ubuntu x86_64 (14.04)
==> default: ---- End output of "bash" "/tmp/chef-script20160920-6143-1sxflk7" ----
==> default: Ran "bash" "/tmp/chef-script20160920-6143-1sxflk7" returned 1
==> default: [2016-09-20T21:56:22+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Gravatar
Chris Oliver (170,390 XP) on

Welp, yeah looks like they stopped compiling for 14.04 because it's fairly old now. Looks like they got up to 2.2.1 https://rvm.io/binaries/ubu...

Ubuntu 16.04 LTS does have 2.3.1 https://rvm.io/binaries/ubu...

I would probably recommend changing your Vagrantfile to use "ubuntu/xenial64" instead of 14.04 trusty which should work. I'm going to update the tutorial to use the newer Ubuntu LTS as well because 14.04 is too old.

Try the newer Ubuntu and see if that works?


Gravatar
Chris Olin on

It's been awhile since this guide was posted. In an effort to help those that come across it, here's a link to a more modern Vagrantfile based off of this guide. Hope it helps.

https://github.com/realchri...

Also, the official Vagrant image for xenial64 doesn't include a 'vagrant' user. See https://bugs.launchpad.net/... for more info. There's a workaround in the Vagrantfile I linked to that references this bug.

Gravatar
Chris Oliver (170,390 XP) on

Thanks Chris! I'm going to try updating the tutorial this weekend using your notes. It's been a while since I've updated this. 🤘

Gravatar
Chris Olin on

Even still, this guide was invaluable for someone like me who had never used Vagrant, Chef, or Ruby before. I kept referring to it and the comments more than anything else.

Gravatar
Chris Oliver (170,390 XP) on

Awesome to hear! Appreciate the updates notes and I should definitely do a screencast on this as well. :D

Gravatar
Chris Olin on

Also worth noting, http://stackoverflow.com/a/.... Found that immensely helpful since this Vagrant box is intended to be used by many people and we want to automate as much as possible.

Gravatar
gafemoyano (220 XP) on

Looks like it's working fine. For vagrant 1.9.3 you have to add , (host_ip: "localhost") to the line config.vm.network :forwarded_port, guest: 3000, host: 3000, at least on Windows machines due to https://github.com/mitchell...


Gravatar
Dima Danko on

Тупорылые авторы статей - после
vagrant up

- пишет:

[email protected]'s password:

и всё блять, какой блять пасворд? долбаебы напишут а людям непонятно. вы хоть проверяли ваш код перед тем как людям предоставлять.


Gravatar
LacosteNYC on

Nice job. But if I change anything in Vagrant file (i.e. add docker, change default ruby version) I get this notice on subsequent
`vagrant up` commands.
==> default: Installing Chef cookbooks with Librarian-Chef...
==> default: The cookbook path '/Users/lacoste/dev/testvagrant/site-cookbooks' doesn't exist. Ignoring...
Same when I try to run `vagrant provision`. So it looks likes whatever chef is doing only works on initial provision, or am I missing something? Thanks!

Gravatar
Matt Yale on

Add a site-cookbooks folder to your directory


Gravatar
Gerald Nah on

HI there, im having this problem after running vagrant up.

Followed all steps from copying both Vagrant and Cheffile into the same directory

C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.3/lib/vagrant/util/is_port_open.rb:21:in `initialize': The requested address is not valid in its context. - connect(2) for "0.0.0.0" port 3000 (Errno::EADDRNOTAVAIL)
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.3/lib/vagrant/util/is_port_open.rb:21:in `new'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.3/lib/vagrant/util/is_port_open.rb:21:in `block in is_port_open?'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `block in catch'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:103:in `timeout'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.3/lib/vagrant/util/is_port_open.rb:19:in `is_port_open?'


Gravatar
Batman on

Hey I keep getting `NoMethodError: undefined method `include_default_source' for Custom resource ruby_rbenv_gem from cookbook ruby_rbenv`

Error executing action `install` on resource '[2.4.0::bundler (ubuntu)] (ubuntu)'

I don't use rbenv on my local machine. Does that matter for installing it on vb?

Gravatar
Ziyan Junaideen on

For me it worked for 2.4.0 but not 2.2.7 which is a requirement for an old project of mine... any clue what caused it?


Gravatar
Batman on

*** ALERT *** If you want a simple vagrant install that is Rails 5, ruby 2.4, and postgres. WITHOUT ansible or Cheffile. Listen here.
While this post was great at some point, it no longer is helpful without doing some troubleshooting. (This guide gave me outdated dependencies and errors that drove me nuts). Download the rails-dev-box and follow their simple instructions. The shell script file does everything without spitting 100's of lines of code. It just works.

Once again, not hating on this guide, I just found a much simpler one.

TLDR; https://github.com/rails/ra...


Gravatar
blazetango (30 XP) on

After I fire the command `vagrant provision`
I get this error

==> default: executable=/opt/chef/bin/chef-solo
==> default: Running handlers:
==> default: [2017-07-17T12:19:39+00:00] ERROR: Running exception handlers
==> default: Running handlers complete

==> default: [2017-07-17T12:19:39+00:00] ERROR: Exception handlers complete
==> default: Chef Client failed. 0 resources updated in 01 seconds
==> default: [2017-07-17T12:19:39+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2017-07-17T12:19:39+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
==> default: [2017-07-17T12:19:39+00:00] ERROR: 412 "Precondition Failed"
==> default: [2017-07-17T12:19:39+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the

I m new to this vagrant, i googled it but was not able to get the right answer to this problem
pls help


Gravatar
Peter Blackledge on

On Windows 10 I'm trying to install Rails on Vagrant on drive D:. After creating the Cheffile and Vagrantfile as directed, the 'vagrant up' command fails with error message: 'D:/vboxes/gems/2.3.4/gems/librarian-chef-nochef-0.2.0/lib/librarian/chef/source/site.rb:309:in `unpack_package!': The package archive has too many children! (RuntimeError)' followed by dozens more file and command errors.
There are a few online discussions - going back several years - about this 'too many children' Chef error. Some possible solutions are proposed, most beyond my technical know-how, and no definite resolution that I can see.
Can anyone point to a reliable answer?

Gravatar
Trung Nguyen (10 XP) on

same issue

Gravatar
Jay Killeen (1,580 XP) on

I'm working through this now. https://github.com/applicat... Looks like this issue was closed long ago but has reemerged. Will try to come back with a fix if I figure it out... which I will probably forget to do once I have figured it out :P

Gravatar
Jay Killeen (1,580 XP) on

Ended up chasing errors most of the day. Windows + Vagrant + Chef for ruby 2.4 and rails 5.1 was not worth the hassle for me as I will be the only dev on this project. Ended up using Vagrant then ssh'ing in and DIY server provision by following the usual GoRails guide -> https://gorails.com/setup/u...

Gravatar
Peter Blackledge on

Glad it's not just me :(

I gave up Chef as not worth the effort and followed a Daniel Kehoe (@rails_apps) recipe to install RoR on a Vagrant Linux VM.

Gravatar
Bob Bannister (10 XP) on
I too have battled with this for ages, using vagrant et al on Ubuntu 17.10. Kept getting the "too many children" error. I discovered that many thought the problem was with "archive-tar-minitar" gem, which used to be true but has been fixed by giving Vagrant a new dependency on "minitar" instead - see here.  So that line of research proved fruitless, however, inspired by Chris' debugging adventures, I dug deeper. The error message located the problem at ~/.vagrant.d/gems/2.3.3/gems/librarian-chef-nochef-0.2.0/lib/librarian/chef/source/site.rb:309. So I had a look and found the following:
303             # Cookbook files, as pulled from Opscode Community Site API, are
304             # embedded in a subdirectory of the tarball. If created by git archive they
305             # can include the subfolder `pax_global_header`, which is ignored.
306             subtemps = temp.children
307             subtemps.empty? and raise "The package archive was empty!"
308             subtemps.delete_if{|pth| pth.to_s[/pax_global_header/]}
309             subtemps.size > 1 and raise "The package archive has too many children!"

I tracked down the first package to fail (system) and examined the value of subtemps to find that there was a second child subdirectory, but its name did not match the 'pax_global_header' string. It was 'PaxHeader'.
I added in a line to delete that..
308             subtemps.delete_if{|pth| pth.to_s[/pax_global_header/]}
309(new)        subtemps.delete_if{|pth| pth.to_s[/PaxHeader/]}
... and Hey Presto! the 'vagrant up' command now completes and we are up and running.

Ah! WAIT... that's not quite true. So much junk lying around from previous attempts that it masked the error in my thinking. PaxHeader may seem to be something useful, so a re-think is required. I'll update you all when I unravel it :)

Gravatar
Khashayar Yo on

Hi There, i get the following error can you please help
/Users/khashayaryousefi/.vagrant.d/gems/2.3.4/gems/librarian-chef-nochef-0.2.0/lib/librarian/chef/source/site.rb:309:in `unpack_package!': The package archive has too many children! (RuntimeError)

Gravatar
Kilian Sprotte (140 XP) on

unsubscripe


Login or create an account to join the conversation.