The purpose of this repository to practice setting up a virtual environment through Vagrant, for developing a Rails application and then deploying the application to a remote service (like Heroku) via Capistrano.
This is also for use for fellow students to learn from and copy.
First download and install the following programs:
You will need Git to clone repositories, but also to use its included "Git bash" if you are running on Windows and do not have some basic Linux plugins installed (via MinGW, Cygwin, etc).
In order to quickly setup the developer environment find a premade manifeat or recipe to use in Vagrant for installing the appropraite software, like MySQL for databases and Apache for serving webpages or applications.
*Note: Any premade Vagrant box will by default have Ruby installed, to allow provisioners like Chef or Puppet to run and install software.
For this Project I will be following SpinUpLabs' Vagrant: Rails development environment article and using their Vagrant file and Puppet manifest to quickly start building an ideal Ruby on Rails developer environment.
Alternatively you could chose to configure your Vagrant install with something like SaltStack. which is a great alternative if you find Chef and Puppet hard to configure or too slow.
SaltStack is Python based script that uses YAML files for
configuration manifests. To use it with Vagrant you will need to install
Salty Vagrant by running vagrant plugin install vagrant-salt
after installing Vagrant.
Quickly searching the web found the "Red Tide Hobo Surfer" repositroy, which should install and setup a Rails environment using SaltStack.
Download and copy your chosen Vagrant file, with provision manifests, into the project's root folder.
Change to the project's root directory in Terminal (Linux or Mac OS X), Git bash or Command Prompt as Admin (Windows);
e.g. cd ~/My\Documents/GitHu/setup_vagrant_rails_and_cap_deploy/
Run the command vagrant up
This will download the appropriate Vagrant box, a virtual machine built for use with Vagrant, and install the software listed in the manifests.
*Note: This will take some time and may fail from timing out when
installing some packages. If that happens restart the virtual machine
with vagrant reload
. This also useful for making changes take
affect after updating the configure manifests.
After the installation has finished, login into the virtual machine with
vagrant ssh
.
*Note: SSH will NOT work in Windows' Command Prompt without additional tools like Cygwin. I would recommend downloading Git and using its Git bash
Once logged in run the command gem install bundler
.
Bundler is a Ruby Gem for managing Gems and their dependencies, ensuring that they will all work with another despite version differences.
Install Ruby on Rails
gem install rails
*Note: If installing any Gems is taking an unsually long time,
Ctrl+c
to cancel out and try again or add -V
(case-sensitive)
or --verbose
to get the full output what it is doing whilst it
installs.
Generate a new Rails Application; e.g.
rails new blog
Change into the new project directory; e.g.
cd /vagrant/blog/
Create the database
rake db:create
And start the server
rails server