- Read Tutorial
- Watch Guide Video
You can just type in Vagrant here and it's gonna be one of the top search results.
So you can see it's vagrantup.com and this is going to give you not only the download instructions but it's also going to give you all of the tutorials that you're gonna wanna see. So this is something that is incredibly helpful because we're gonna be using Vagrant throughout this entire set of courses. So before we install it, let's just kinda talk about what Vagrant gives us.
So if we're working on a Windows machine, we would have a large number of installation and environment requirements if we wanted to build React applications. Then say we wanted to build Python applications, we'd have a full different set of items and independencies that we'd have to install in order to write and execute Python code, and the same thing would happen for Ruby on Rails and for MySQL and for pretty much anything you can imagine.
What Vagrant does is Vagrant gives us the ability to skip through quite a bit of the dependency and environment setup and it sets it up for us. So what we can do is we can install what are called boxes and you can see right here in the documentation this is an example and it's one we're going to test out.
We can install this, this will install a full operating system for us, a virtual operating system, so it's going to do that but as you're gonna see as we go through the courses, we're gonna do this for each one of them which means we're gonna be able to say Vagrant init and then call some name and it's gonna give us all of the development environment items we need in order to build React native applications or a Ruby on Rails application, anything you can imagine, we can simply call this init function, pass in the box we want to use and then it's going to build and wrap-up an entire development environment and this is gonna be the same whether we're on Windows, on Mac or any type of operating system.
So this is a very powerful tool, I've used all kinds of different environment setups through the years, everything from just making my own custom development environment through trying to use other tools and Vagrant really is one of the most streamlined and easiest to customize out of all of them.
So let's get started. We're going to start by clicking Download and then picking out our operating system.
So I'm gonna pick out the Windows 64-bit 'cause that's the type of Windows machine that I'm on and as you can see, that's 210 megabytes, so depending on your internet, this is going to be done in just a few moments or it might take a little bit of time. So that's going to install the installer and then it's gonna be a pretty basic setup, kind of like how we did with VirtualBox, it's going to, we're gonna be able to use pretty much all of the key defaults.
So I'm going to, once that's done, I'm just gonna click on it, and that's going to bring up the installer. So here I'm going to click Next, accept the terms, hit Next again. Next and Install. This is going to pop up another window and it covers the whole screen, you won't see it but it'll do the same on your system and you'll just click Yes whenever that happens, and now it's going to go through the full install process.
So this is gonna be pretty basic and then we only have one item that we need to run in order to get this working on a Windows machine. So on Mac this is not required, but on Windows we need to make one small configuration change and I will be putting this code in the show notes so that you will be able to have access to it.
So as soon as this is done, I'm gonna walk through the one piece of configuration that we need to take care of. So let's get started as soon as that is done. And I'm gonna fast-forward this until it's completed. Okay, it looks like it is all done, so we're gonna click Finish here and then it says, "You must restart your system for the configuration changes made to Vagrant to take effect."
So I'm going to stop the recording right now, I'm gonna click Yes, so it's going to take me through and it's gonna restart the system. Do the same on your side and when we come back, we will be able to take care of the configuration item. And we're back, and we are going to have to restart our system once more after this configuration change, but let's make it first.
I'm gonna come down all the way down to the bottom left window and just start typing cmd. This is gonna be your Command Prompt and go to the Command Prompt, don't just click on the application, right-click on it or you also could come over here and you want to run it as an administrator.
So you can also right-click and click Run as Administrator and the reason why we need to do this is because the change we're gonna make is actually going to kind of reconfigure how the system works in relation to virtualization. So that has to be something that only an administrator can do. So you're gonna click on that, it's going to pop up another window saying do you want to allow this to make changes to the device, click Yes and now we have the Command Prompt.
So right here I'm going to paste in some code, and this code is gonna be in the show notes, so just feel free to go and to grab that right out of the show notes. We're going to edit a configuration and we're going to set the hypervisor launch type to off. This is something that's required, Vagrant will not work if this is not run. So click Enter and as long as it says the operation was completed successfully, then we're good to go.
I'm going to close out of this and I'm gonna stop the video once again, restart the system because in order for this to work, you will need to restart. And when we come back, we can test to make sure that our Vagrant installation worked properly. And we're back once again and now we are ready to test out our Vagrant installation and see if we can create a full development environment.
So I'm gonna go back to the Vagrant homepage here and this has all of the code we need in order to ensure that Vagrant is working and we can build full environments. So let's now go and open up PowerShell. You can also do this in the Command Prompt, but I prefer using PowerShell and that's what I'll be doing when I'm testing it out.
So I'll open up Windows PowerShell. Once again, we need to run this as an administrator 'cause we're working with virtual machines. So click Yes when that pops up and now you can see that we're accessing the system.
I'm gonna create a code file in our core system so I'm gonna type in mkdir, that stands for make directory and I'm just gonna call this code. You could call it anything you want, you could call it projects, anything like that, and so that's gonna create a code directory. Now I'm gonna cd into it, cd stands for change directory. So cd code and hit Enter and now you can see in the path we're in the code directory.
Now I'm going to create a Vagrant demo project, so let me call this one vagrant-demo and then once again I will cd into that.
command prompt
mkdir vagrant-demo
cd vagrant-demo
So now you can see we're on our Windows system, we're in our code directory in vagrant-demo.
If you type Control + L, that'll take you up to the top and will clear out the input. So now, we can go and look at this code over here and you can just copy it or you can type it out. I'm gonna switch back and if you simply hit the right-click button on your mouse, it will paste that in. So this is going to type Vagrant init hashicorp/bionic64
, it's a very lightweight version of Linux. And so I'm going to run that code and what it's gonna do is it's gonna go out to Vagrant itself and it's going to create a Vagrant file.
So now if I type ls and that lists out all of the files, you can see we have a Vagrantfile there, so that part of it it's working.
Now let's type vagrant up. So we're just following the directions that they gave us there on the homepage. So it's bringing up the default which is VirtualBox so you can see this is the reason why we had to install VirtualBox because it's using that for the virtualization system. It's going out, it's finding this very tiny little operating system here, it's pulling it in and this might take a few moments in order to work.
Some of the other ones that you'll see that we're going to build out can take up to a few minutes. If it's a full operating system and a large number of dependencies, it can take a while. So just be prepared for that and it's also based on how fast or slow your internet is. So I'm going to fast-forward until this full progress is completed. Okay and it looks like it all worked perfectly.
So I'm gonna type Control + L to clear all of that out and now let's type vagrant ssh
and if this all works, so if vagrant up worked properly, ssh is going to allow us to actually jump inside of our Vagrant box and work with it just like a different operating system. So when I type vagrant ssh, you can see that our entire command prompt now has changed.
So even though we might be on a Windows machine, technically we are now typing on a Linux box. So I can run commands here that are commands you can only run inside of Linux. And so this is really helpful because as you can see right now, we've completely changed the entire way that PowerShell even looks and how it operates. And so this is what we're gonna be using, this is kinda the base of all of the development environments we're gonna be building out. When we type vagrant up, it not only installed the operating system, it also connected and wired up our entire system, our computer, so that it could work with a custom set of virtualization boxes.
If you've never built out a development environment before, then you might not be able to appreciate how painful this can be. I have had times where I spent literally days properly building out a development environment and fixing bugs and getting the dependencies to work together, Vagrant can do it for us in just a few minutes, which is really helpful.
Now that we have this, if we wanna get out of this ssh session, then I can type Control and then D and that's going to log us out. So you can see that that connection is now closed and we're back in the normal type of terminal.
command prompt
control + d
Now one thing to keep in mind, when we are using Vagrant, we are taking up quite a bit of space on our local machine which can be a problem. So right now even though we might not be sshed into the machine, there is still a machine running and you can check that by typing in vagrant status
and this is going to look and it's gonna see if any Vagrant machines are running and you can see right here that there is. It's a default one that's running on VirtualBox, and it also gives us some helpful tools.
So if we want to shut it down or we want to suspend it or we want to kill it, then we can run these commands. So say that we want to just kinda put it to sleep, we don't want it to take up all of these really big resources on the machine. I can type vagrant suspend
, this is similar to if you just wanted to put your computer to sleep. So I can type vagrant suspend and that's going to suspend the system.
So you can see it's saving the virtual machine's state and it's pretty quick. Now if I type in vagrant status, it's gonna say that it is running but it's saved and so if we wanna get it back up, then we just have to type vagrant up again and then it's like waking up your computer. It's gonna happen pretty quickly, as you'll see it's gonna be much faster then when we had to install the entire thing the very first time.
So vagrant suspend is one of the fastest ways of being able to save the state of your virtual machine but being able to just decrease the resources that your system is using and you can see that worked perfectly. Now another option that's a little bit more forceful is to say vagrant halt and that's actually going to be shutting it down. This is the same as if you were to shut down your computer and so that's going to change the status as you'll see here in a minute. So if I type now vagrant status, now you'll see it's not just saying saved, now it's powered off.
And if you hit Up on the keyboard, if you're not really familiar with working with PowerShell, you can access your full history, so all the commands that we just typed in, you can access all of those. So now I could type vagrant up again and that's going to allow us to access that Vagrant box, it's gonna turn it back on. It might take a little bit longer depending on your system but it's going to be very similar to how suspend works and then we'll be back up and we will go through one more command after this and your initial Vagrant tutorial is gonna be all good to go. So you can see there are a few more commands that have to be run in order to get that working.
So now let's actually kill it. So I'm going to just say vagrant destroy
and this kills everything. So this is not going and it's gonna ask you yes or no if you wanna actually kill it, so I'm gonna hit Yes, this is going to remove all of the files, so it's going to delete all of the files for the code that's needed in order to run the operating system.
Now this is not going to delete your project. So say that you create some type of React or a Rails project or something like that, this isn't going to delete that code, we're gonna walk through that in a future guide and you'll see how that works. This is simply destroying all of the code needed in order to run Vagrant. This didn't delete the Vagrantfile as you'll see, so I could type vagrant up right now and it would install everything from scratch, so take another few minutes, but those are those three commands for turning your boxes off.
So great job if you went through that. If you had any issues at all, please go and add them, create a support ticket on the Bottega Support site and a mentor will be able to walk through any issues that you might have ran into. With all of this in place, in the next guide, we are going to install our code editor.
Resources
Code to run in the command prompt:
bcdedit /set hypervisorlaunchtype off