Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Trouble setting up treehouse VM with vagrant

Hello, following along with video for setting up rails environment using vagrant. When I try the command 'vagrant up' it looks unable to get pass ssh authentication. The following is from my terminal:

Macintosh:treehouse tomlewis$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> 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: 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: treehouse default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Authentication failure. Retrying...

I eventually have to end the process. At this point I am able to run command "vagrant ssh", I'm prompted for an ssh password, I enter 'treehouse', and it appears I am in the VM as treehouse. However, there are no files present, the user folder is blank inside the VM.

Macintosh:treehouse tomlewis$ vagrant ssh treehouse@127.0.0.1's password:

Welcome to the Treehouse VM! For help, please see the forum at:

http://teamtreehouse.com/forum Last login: Fri Jun 20 00:31:58 2014 from 10.0.2.2 Agent pid 1927 treehouse:~ $ ls treehouse:~ $

I tried 'vagrant destroy' and 'vagrant up' and also tried on another computer and ran into the same issue. I tried the 'getting started' example on the vagrant website and was able to get that machine running correctly. Vagrant seems like a really cool tool, wish I could get the treehouse machine running though. I'll post back if I figure anything out.

3 Answers

Curious. It doesn't sound like vagrant was able to complete the provisioning. Sometimes launching a vagrant VM initially can take an exceptionally long time especially if it has to download data from the internet. I've had a VM take hours to complete.

You can try asking vagrant to run the provisioner:

First, shut down the current VM if it isn't already.

treehouse $ vagrant halt
==> default: Attempting graceful shutdown of VM...

Then run the provisioner again.

treehouse $ vagrant provision

If that doesn't work, try to destroy and rebuild the VM

treehouse $ vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Destroying VM and associated drives...

Rebuild the VM from scratch.

treehouse $ vagrant up

Hopefully that helps!

Gary McKay
Gary McKay
1,896 Points

I have the same issue, only when I execute "vagrant provision" I get an error, saying can't find "cheffile" I will try the destroy command

Hmm it may be that the Vagrant file is corrupt - and requires a treehouse tech to take a look at it.

In the meantime, you can provision your own if you'd like:

Setting up Vagrant

  1. Create a new directory for your vagrant and change directory.
$ mkdir vagrant-rails
$ cd vagrant-rails
  1. Initialize your vagrant. This goes out to the internet and grabs the popular ubunty/trusty64 vagrant box.
/vagrant-rails $ vagrant init ubuntu/trusty64

One thing you'll want to do, is open your Vagrantfile and add the last line.

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 3000, host: 3000
  1. Launch the vagrant
/vagrant-rails $ vagrant up
  1. SSH into the vagrant
/vagrant-rails $ vagrant ssh

Then you can follow the instructions at gorails.com/setup/ubuntu/14.04 to install Ruby using rbenv, then Rails. I'd suggest sticking with SQLite3 for the tutorials, as setting up a database is a pretty deep rabbit hole you may not want to travel down.

Working with your Vagrant

Navigate to the shared folder from inside your vagrant:

$ cd /vagrant

You should see your Vagrantfile in this directory.

Now create your rails application:

vagrant/ $ rails new myapp

This will create your rails application in the shared directory.

Launch your Rails Server

One "gotcha" is when you launch you rails server you will need to bind thte server to 0.0.0.0

$ rails s -b 0.0.0.0

Now if you go to localhost:3000 in your browser, you should see the Welcome to Rails screen.

Work with Rails

Okay, so now that you've got your initial application set up, what now?

  1. Open a new terminal tab with Command + T on a mac.
  2. Navigate to your /vagrant-rails directory. You should see your rails application folder.
  3. Navigate into your project directory
vagrant-rails/ $ cd myapp
  1. Launch your editor
vagrant-rails/myapp/ $ subl .

And viola! You can now work with your Rails application.

I typically use git from my mac (not from vagrant) to manage my codebase as well.

Gary McKay
Gary McKay
1,896 Points

Ahhh cool. I will give it a try, thanks

Gary McKay
Gary McKay
1,896 Points

Just wanted to let you know, that this works. Thanks! Any idea on when the Vagrant Teamtreehouse VM will be looked at

Excellent Gary! In the meantime, I'll ask Nick Pettit to follow up for you on the status of the Teamtreehouse vagrant.