Vagrant Tutorial - Running a VM For Your Local Development Environment

LearnCode.academy · Beginner ·☁️ DevOps & Cloud ·12y ago

Key Takeaways

Vagrant tutorial for creating a portable local development environment using Virtual Machines, mirroring staging and production environments for streamlined development workflows.

Full Transcript

so if you are at all passionate about server Administration or uh Dev Ops or making deployments uh or if you're wanting to get into that world uh vagrant and you don't know what vagrant is vagrant is awesome it is a tremendous tool for learning all that stuff basically what it does is it allows us to On Demand spin up virtual Linux boxes you could spin up four of them on your machine and run a you know run a load balancer and test failover stuff or you could spin up a virtual vagrant box and configure it and try to do deployments to that virtual machine it's a great playground for learning stuff and it's very useful for a lot of other things uh so let's go ahead and get into how to use vagrant to spin up a virtual Linux machine and later on once I'm done I'll kind of tell you some more philosophy on why you should use it for local development environment instead of wamp or M or stuff like that and how devs are using it but for now let's get into the fun stuff and let's actually use it you're going to want to go to vagrant up.com and you're going to want to download it you're also going to want to go to if you don't have virtual box installed yet virtualbox.org and download it and install it and all of this will by the way be in a gist that I will put in the description so I don't leave you hanging um and so those are both installed I should be able to go vagrant DV and you should be running 15 or newer uh for what we're going to be doing today so then all you have to do is go to vagrant cloud.com uh and we are going to pick some boxes that we want to install on our system so go to vagrant cloud.com and go to popular and the most popular ones are the precise 32 abunto box and the precise 64 uh 64 is more powerful but it's going to consume more RAM on your computer uh this precise 32-bit takes about 300 megabits of ram megabytes of ram to run and this takes more like 5 or 600 so I usually run the 32s unless I have a reason to run the 64-bit system cuz I can run a whole lot more of these especially if you only have like 4 GB of RAM or so you're going to want to run a 32bit uh so what you're going to do is vagrant box add and then that and that will download that box image it won't install anything on your system yet it's just going to put that box on your machine so we can now spin up you notice I've downloaded it before it'll take you a few minutes to download it if you have not um but now I can spin up as many precise 32 boxes as I want as long as my computer can handle it uh so now you're just going to go to you know install as many boxes as you want and now you go to the folder that you want to be running uh to actually create your virtual box in and you're going to go vagrant in knit and once again that um let me see if I can do no I can't Tab and have it auto correct uh hash cor precise 32 there we go so I'm going to now knit that um and now I can go vagrant up and so now I'm going to spin up my precise 32 box it's going to import the image it's going to start booting up my Linux box and it's also going to add a vagrant user and create SSH privileges for that user so I don't need a password um there we go now I'm running a Linux box on my machine so I can now go vagrant SSH and it's going to ssh in as my vagrant user so there we go I'm now on the precise 32 box as far as my computer's concerned this is a server out on the internet and I am sshing into it so I can go pseudo apt git install git I'm going to start installing GitHub on my new machine um that'll take a little while probably a minute or two so I'll cancel and pretend that was successful um so there we go I'm going to exit out now and let's go ahead and make this even more realistic let's give it an IP add address and a domain name uh so we can actually run it as a web server and as a fake uh domain name so we don't even need to purchase hosting uh let's go ahead if I LS I exit it out of that box and I'm back on my machine um and so what you can do now is let's go ahead and open that vagrant file in Sublime Text I'm going to change syntax to Ruby so it looks pretty okay so it created a vagrant configuration file for me and the only only line in it is this all the other ones are just kind of some boilerplate stuff for me and the only thing I'm going to add is I'm going to uncomment this private networking and I'm going to give it an IP address 55. 55.55 you can make up pretty much whatever you want um and so my IP address is going to be running that I'm going to save and quit and now I'm going to run vagrant reload so now it's going to uh re load my box with my new configuration it's going to shut my box down reboot it and now I'm going to be running you'll see that it is now making a connection to something it doesn't spin forever it makes a connection to something but it stops right away so it doesn't really know uh there's there's no Apache or there's no web server running on my Linux box uh so the connection goes through but I don't get an HTML file or anything so let's go ahead and install engine X let's go I'm going to vagrant SSH so I'm going back into my box if you're not familiar with engine X engine X is like a substitution for Apache uh usually it's what you use when you're running a node.js application in production we'll get into that in probably the next video um so let's go pseudo apt get let's update our apt get application real quick that's always a good idea whenever you spin up a box the first thing you should do is run aptg update um apt get install engine X so let's go ahead and install the engine X web server it's very light takes almost no time that's done and now all we have to do is go service we do pseudo service engine X start there we go it started and now if I run there we go welcome to engine X is my default so now I am running a web server on 55.55 55.5 now the only thing I want to do is I want to actually make this map to a domain name so let's go ahead and go we're going to go pseudo open Etc hosts uh and we're going to do this in I'll do in Sublime Text so here we are if you've never messed with a host's file before uh it's it's very basic there's basically just two rules don't change anything that's in here already um the other rule is any IP address you type in you can assign a domain name to it so now when anything on my machine goes to my awesom site.com it's going to send it to this IP address instead of whatever IP address it would normally send my awom site.com to I'm going to save it it may ask for your password um so now I should be able to go to mysite.com and there you go it's going to my new server welcome to engine X so what we've just done is we have spun up a Linux server you can now configure it however you want to um and you can then make sure that mysite.com goes to your server instead of whatever IP address you normally go to um and so what lots of times people will do is they'll actually do this is they'll go dev. awom site.com ask for my password and so then you'll go to dev. mysite.com for your local machine and then you'll go to my awom site.com for your production machine so I want to talk real quick about why you would do this two reasons one you want to play around with Linux machines and you want to be able to destroy them when you're done okay so that's that's a great reason right there um uh the other day I was running I think I already mentioned I was running you know tons of Linux machines behind a a fake Linux machine running a load balancer I was able to see what happens when memory started getting low on this machine and all these other things you can totally run tests you can set up a fake server and practice making command line deployments to that server without blowing up your production server um so there's that there's just practice and then the other big big big big big way that people are using vagrant is they are running a vagrant file in the repository for their project um and so what this is going to do is whenever your project is open you're going to be able to instead of running map uh which will install install Apache MySQL and PHP on your Mac uh or on your Windows machine you can actually just run a vagrant box that's configured exactly like your production web server and then you can give it an IP address and a domain name like dev. awesome website.com and so now you don't have your machine is not tied to one project uh cuz Lots of times what will happen is a Dev will have a problem on their machine uh but they're not seeing that problem on another dev's machine because they're running a different version of PHP or they're running a different version of Ruby or they're running a slightly different version of Mac OS 10 or something and this way the code you're writing is running on the exact same virtual box that all the other devs on your team are running their code on um uh another nice thing is that whenever vagrant makes that SSH connection you can actually access all the code from your repo right here from within the virtual machine so the virtual machine is running and it's running the code from your GitHub repository that you're editing on the machine you're on now if that makes any sense it basically solves the problem of well that doesn't happen on my machine why is it happening on your machine which happens to developers all the time so there's my Spiel there's my little Soap Box presentation for you I I hope you have a ton of fun with vagrant in the next video we're going to be getting into running um we're going to run a vagrant box and we're going to install engine X as a front end to our node.js application and then after that we're going to set up a load balancer so engine X can be running to multiple node.js servers uh and handling failovers and stuff like that hope you enjoyed the video

Original Description

Vagrant and VM's can RADICALLY shape your development workflow. Instead of every developer working on their own local server with their own configuration, you can configure a portable local environment that exactly mirrors your staging and production environments. Now developers can spin up this environment on their machine and work completely locally without having to change their machine configuration to accommodate the project they're working on. Also, each project they work on can have it's own VM running it's own configuration that they can spin up. Also, Vagrant provides an easy-to-destroy environment to practice your Linux server administration skills! Here's the Gist on how to follow along: https://gist.github.com/learncodeacademy/5f84705f2229f14d758d -~-~~-~~~-~~-~- Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device" https://www.youtube.com/watch?v=fgOO9YUFlGI -~-~~-~~~-~~-~-
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from LearnCode.academy · LearnCode.academy · 35 of 60

1 Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
2 Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
3 How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
4 Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
5 Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
6 CSS Tutorial - Web Development Tutorial for Beginners (#5)
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
7 Node.js tutorial for beginners - an introduction to Node.js with Express.js
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
8 Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
9 Javascript Tutorial - Programming Tutorial for Beginners Pt 1
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
10 Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
11 AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
12 WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
13 YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
14 BOWER! - Streamline Web Workflow with Bower Package Manager
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
15 Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
16 GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
17 GITHUB PULL REQUEST, Branching, Merging & Team Workflow
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
18 Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
19 jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
20 jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
21 jQuery Tutorial #1 - jQuery Tutorial for Beginners
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
22 Node.js MongoDB Tutorial using Mongoose
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
23 Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
24 WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
25 jQuery Tutorial #4 - DOM Traversal with jQuery
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
26 jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
27 jQuery Tutorial #6 - Building a jQuery Image Slider
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
28 jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
29 jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
30 jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
31 jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
32 How to put your website online - how to FTP to a domain & upload files to a webhost
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
33 Basic Terminal Usage - Cheat Sheet to make the command line EASY
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
34 SSH Tutorial - Basic server administration with SSH
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
Vagrant Tutorial - Running a VM For Your Local Development Environment
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
36 Sublime Text Favorite Packages and Workflow
Sublime Text Favorite Packages and Workflow
LearnCode.academy
37 What Makes Javascript Weird...and AWESOME - Pt 1
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
38 Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
39 Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
40 FREE REST API - Practice Developing Javascript AJAX Apps with this API
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
41 Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
42 Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
43 Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
44 Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
45 Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
46 Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
47 Web Development Advice - Interview with Dev Tips
Web Development Advice - Interview with Dev Tips
LearnCode.academy
48 How the Internet Works for Developers - Pt 2 - Servers & Scaling
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
49 How the Internet Works for Developers - Pt 1 - Overview & Frontend
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
50 HAPROXY vs NGINX - 10,000 requests while killing servers
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
51 Node.js Cluster - Boost Node App Performance & Stability with Clustering
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
52 Web Dev Training with Treehouse
Web Dev Training with Treehouse
LearnCode.academy
53 What is Node.js Exactly? - a beginners introduction to Nodejs
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
54 How to deploy node.js applications #1 - spin up a server
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
55 Deploying node.js applications #2 - provision server & setup flightplan
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
56 Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
57 Mobile Web Design - Coding Workflow For Mobile Websites
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
58 WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
59 GRUNT TUTORIAL - Grunt makes your web development better!
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
60 STOP USING FTP!  - How to Deploy with Flightplan over SSH
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy

This tutorial teaches how to use Vagrant to create a portable local development environment using Virtual Machines, allowing developers to mirror their staging and production environments locally for streamlined development workflows. By following this tutorial, developers can improve their development efficiency and reduce configuration inconsistencies. The tutorial covers the basics of Vagrant, VM configuration, and environment mirroring.

Key Takeaways
  1. Install Vagrant on your local machine
  2. Create a new Vagrant project
  3. Configure the Vagrantfile for your VM
  4. Spin up the VM using Vagrant
  5. Configure the VM to mirror your staging and production environments
  6. Test and verify the environment
💡 Using Vagrant to create a portable local development environment can significantly improve development efficiency and reduce configuration inconsistencies across different environments.

Related Reads

📰
Coding agents made us write code 3x faster — and CI became our bottleneck
Learn how to optimize CI/CD pipelines by distributing integration tests across multiple GitHub Actions shards on a dedicated server, resulting in 3x faster coding with agents
Medium · DevOps
📰
The Night the Cluster Fought Back
Learn how to use Cilium, Falco, Kyverno, and Velero to improve cluster security and management
Medium · DevOps
📰
GitHub Actions Caching: What Actually Gets Cached in Each Language
Learn what gets cached in GitHub Actions for each language and how to optimize your workflow
Medium · DevOps
📰
Discipline, Not Luck
Learn how discipline and careful planning can lead to successful DevOps projects, such as a solo GitLab upgrade, and why it's essential for professionals to prioritize these skills
Medium · DevOps
Up next
Trace LLM P95 Latency Spikes in Python with OpenTelemetry + Prometheus
Professor Py: AI Engineering
Watch →