Skip to content

☔ Learn how to use Vagrant to easily build complete development environments.

Notifications You must be signed in to change notification settings

dwyl/learn-vagrant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Vagrant Logo

Vagrant lets you easily package an environment and share it with anyone.

Key Benefits

  • Run your production OS/Stack on your local machine with minimal overhead.
  • Consistently set up a new machine with only a few commands.
  • Never have to worry about which version(s) of packages your colleagues have on their machine.

Also ...

  • Isolate anything new/experimental/untested from your main OS (e.g: want to play with a new NoSQL database? spin up a Vagrant VM in seconds without installing XYZ-DB as root on your main machine!)
  • Side-step Security Vulnerabilities by using a VM! (Don't want to run Java on your machine because you're sick of having to update it each time a new Security Vulnerability is discovered? Install it using Vagrant!)

Will it work for me...?

YES! You can run vagrant on the most popular operating systems;
Windows Mac Linux
Microsoft Windows, Mac and Linux (most flavours).


Requirements

  • Basic comfort with command line
  • Internet Connection (for downloads)
  • Time: 30 mins

Up & Running in Three Easy Steps

1. Download & Install Vagrant + VirtualBox

First thing you need to do is install VirtualBox:

https://www.virtualbox.org/wiki/Downloads

(Vagrant uses a "headless" VirtualBox Virtual Machine (VM) - you don't need to know what that is or how it works just trust that it does its job really well, is well documented and extensively tested)

and Vagrant:

http://www.vagrantup.com/downloads.html

2. Clone this repository

git clone https://github.com/nelsonic/learn-vagrant.git && cd learn-vagrant

This means that you will now have the only file you need in your directory to get Vagrant up and running: the Vagrantfile. This file adds the configuration you need to the vagrant box.

The one in this repository updates Ubuntu, installs Node.js, updates it and prints out the version. There is also commented out code there that would have installed MongoDB and run some tests. If you're setting up your own configuration, copying this file would be a good place to start!

Windows users will also need a vagrantfile_ssh.txt file - in the windows-only directory of this repository.

3. Boot Ubuntu (installs latest Node.js)

Boot the Vagrant Box:

vagrant up

(this will install ubuntu and node.js so may take a few minutes - depending on your internet connection)

Anything you do within the directory you're currently in will now take place exclusively in your Vagrant environment.

Login and Explore

SSH (login) to the Vagrant Box:

vagrant ssh

to exit simply type exit in the terminal (this logs you out but Vagrant will still be running):

exit

Windows Only

Because windows does not come with an SSH client you will need to install one.

Todo



Other useful commands

Shut down the Vagrant Box

vagrant halt

This will shut down while preserving the state of the machine, much like hitting the 'pause' button.

Need to Kill it?

vagrant destroy

This will stop the machine altogether and you will no longer be operating within Vagrant in the directory.

More Detailed Instructions

Create our base Ubuntu Box:

vagrant box add base https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

This command will create a box called "base" and download the base install of ubuntu version 14.04 (latest)

you should see:

==> box: Adding box 'base' (v0) for provider:
    box: Downloading: https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
==> box: Successfully added box 'base' (v0) for 'virtualbox'!

This will be useful if you want to install the box globally so that you don't have to download and install it through the Vagrantfile every time you run vagrant up.


Useful Links

Which box should I start with?

I'm using: https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

Install Node.js on Unbunt:

Tutorials

Background

Why do we even need Vagrant?

For better or worse, people still use different operating systems for their development machines. While many have made the switch to Mac or Ubuntu, most people are still developing on Windows. Using vagrant as a VM to run your production OS locally means you can keep everything consistent everywhere, regardless of your local OS.

How did we get here?

In the dark ages of development (pre 2012) people had to manually install all the dependencies for projects, often leading to version conflicts and incompatibilities. 😢

Enter Vagrant to save the day!

Now you can keep a single file listing all the dependencies required to boot a fully-functional development machine using a single vagrant up command.


Minimal Overhead

CPU

Vagrant CPU Consumption

Memory

Vagrant Memory Consumption



Discussion

Docker vs. Vagrant

Next

Vagrant on Digital Ocean / AWS ?

Inspiration / Thanks

Special Thanks to Joaquim Serafim for encouraging me to learn/use Vagrant
see: https://github.com/joaquimserafim/vagrant-nodejs-redis-mongodb

About

☔ Learn how to use Vagrant to easily build complete development environments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •