You are currently viewing Ubuntu Rails VM Tutorial: Launch

Ubuntu Rails VM Tutorial: Launch

Part 3 of 5 of the Ubuntu Rails VM Tutorial series

Part 3 of the Ubuntu Rails VM tutorial covers how to launch your prepared Ubuntu virtual machine on Windows for Ruby on Rails development.

This step requires that you’ve read the tutorial introduction in Part 1 and have completed the setup steps described in Part 2.

1.0 VM Launch

Switch to the deployment directory path and launch the virtual machine.  Replace my deployment project path with your own:

$ cd /f/dev/work/vm/ror
$ ./launch.sh

This launch script will take several parameters or run on defaults.  It performs the necessary steps to boot the virtual machine.

Launch Script Warning

Using the “–new” parameter for “launch.sh” or “vagrant destroy” will erase anything you’ve added, installed, or coded on the vm since Vagrant provisioned the vm with Ansible.

The first time it runs, pay attention to log messages as they fly by.  Due to changing versions, you may need to troubleshoot warnings or errors (see the next two sections).  While I have documented smaller issues in the comments of the scripts and Vagrant and Ansible files, larger issues or confusing items will be documented in the GitHub repository.

2.0 Test-Drive the VM

2.1 Accessing the Web Server

If your vm is successfully provisioned, its web server can be accessed from any browser on your current network by the address specified in the Vagrantfile:

 http://192.168.33.10/ 

2.2 Remote SSH

To connect to the virtual machine, from the command line in your deployment project directory:

$ cd /f/dev/work/vm/ror
$ vagrant ssh

View and explore to your heart’s content.  

To exit the ssh session, type

$ exit

3.0 Ruby on Rails

3.1 Generating a Rails App

You can also test your rails system by generating an app. If you’d like to follow the the Rails guide available here, let’s generate some code:

Shared Code Directory

The “code” subdirectory shown below is shared between Windows and the Ubuntu VM. Changes made on the Windows side appear on the Unix side, and vice versa.

$ cd /f/dev/work/vm/ror
$ vagrant ssh
$ cd ~/code
$ rails new blog

If everything is installed correctly, you’ll see the rails generation code fly by.

Warning

Again, anything on the VM, including what’s in the code directory, is destroyed when the VM is destroyed.

3.2 Accessing the Rails Server

Now that you have a Rails app, you have a Rails server. You can access the Rails server by

  1. On the VM,
$ cd ~/code/blog
$ rails server -b 0.0.0.0

2. On the Windows host, open a browser to

 http://192.168.33.10:3000/ 

You should see the”Yay!  You’re on Rails!” page in your browser.

3.3 Exiting the Ruby Server

You can terminate the Rails server on the virtual machine by Ctrl-C

4.0  Done with the Virtual Machine?

4.1 Commands to Stop and Exit

To leave the ssh session on the vm and return to your terminal prompt on the Windows side, just type

$ exit

To stop the virtual machine, on the Windows machine in the terminal window type,

$ vagrant halt

To destroy the virtual machine and the apps, code, and data on it, on the Windows machine in the terminal window type,

$ vagrant destroy

4.2 VM States and Existence

This might be a good time to review vagrant commands such as “vagrant halt” and “vagrant destroy”.  See the vagrant command reference online.

5.0 What’s Left?

This concludes the main part of this tutorial. To wrap up, I’ll cover details on error handling and troubleshooting.

CR Johnson

As a software engineer with over a decade of experience working for Fortune 50 companies developing software for Windows, the web, and a few interplanetary spacecraft, she's programmed in a plethora of languages including the C#/ASP.NET stack and, recently, Rails. She has tweaked more CSS files than she can count and geeks out a little on data and SQL databases. In her spare time she works on her first novel and enjoys bicycling and dark chocolate.