2.1 Create a Vagrant Virtual Machine
If you don't have access to a physical machine running Linux, don't fret. You can simply create a virtual machine to simulate a physical Linux environment. In this lesson, I will show you how to get started with a Vagrant virtual machine.
1.Introduction2 lessons, 05:56
2.Get Started4 lessons, 32:10
3.Conclusion1 lesson, 01:12
2.1 Create a Vagrant Virtual Machine
Let's start by getting our development environment and ultimately our VM with Linux running on it, up and running so that we can start to see how we can get access to Swift on another operating system. So you can head over to swift.org and take a look at getting started, and you'll see a little bit of information here about how to get started with Swift. Where to go ahead and download it. How to install it, especially on Linux, this is where we're gonna have to pay attention to. We have to install the Apple C compiler first, the C lang compiler. But as you see here, we can use apt get while we're on Linux. To go ahead and get that, we'll take advantage of that in a few moments as you'll see once we start working with Vagrant, and then we have to set the location of Swift into our path so that we can get access to it. Then once we get to the command line, we'll be able to just access it via the Swift command line. And that's really all we wanna get to by the end of this lesson. So how are we gonna do this? Well, there's definitely a lot of different ways to do this, but we're gonna take advantage of some of the nice features built into Vagrant to take care of all this stuff for us. So let's start by heading over here to take a look at the Vagrant docs. Now, if you've never used Vagrant before it can seem a little overwhelming. But it's really not too bad. And I'm gonna show you just the absolute basics you're gonna need to get up and running, at least for this course, using Vagrant in a few moments. Now, as you saw before, we're gonna be able to download Swift and install all the bits and bytes and that's all great. But we need an operating system. We need Linux of the version that we wanna use. Remember either Ubuntu 15, 10 or 14, 04 but where's that ultimately gonna come from? Well you can just go ahead download it if you want or you can head over to cloudimages.ubuntu.com and you'll see a list of things here. And if you go towards the bottom, you'll see Vagrant images. So let's go ahead into vagrant, the directory. And you're going to see a number of different versions here, 12, 14, and two of the 15 versions. And you can use either 1404 or 1510, whichever one you want. And, we'll just use trusty for this, we'll use 1404. And, we'll just go ahead into the latest directory here, the December 18th of 2015. We'll go ahead into that directory, and what we want to pay attention to here is the trusty server cloud image amd64 vagrant disk box 1. That is the one we're going to be paying attention to. Not only am I going to be paying attention to it, I also want to grab this URL, so I'm simply gonna right click on this link. Select copy link address. So, now what I want to do is I want to get started with all of this stuff. So, I'm going to go into Finder, or you can use a command prompt if you want. And I'm simply gonna create a new folder here on my desktop. And I'll call this Swift hyphen Linux. Now that I've done that, I need to be able to go into here and I need to be able to create a vagrant config file, and that file is going to be called vagrant file with no extension on the end. Now you can use any sort of text editor, you want. You can use Vim, vi, TextEdit, or all sorts of crazy things. Whatever you want, I'm simply going to use TextEdit just like that. So what I'm going to do here is I'm gonna start to write in here my configuration file and then I'm gonna save it into that directory. So, Vagrant, once again you can head over to the vagrant documentation to follow along if you'd like, or you can just kind of follow what I'm doing here. So, we're gonna start by specifying a vagrant.configure. And this is gonna have open close parentheses, and we're gonna specify the number 2 in there. Now the 2 is because the current version of Vagrant that we're using to configure this Is going to be version two, and that's simply all that that represents. Then what we want to do, we want to be able to configure this. We're gonna use the keyword config, if I can spell that correctly, config. And we're gonna drop down here, we're gonna start to do this configuration. So let's indent a little bit here and we'll simply say config.vm.box. Now what this allows us to do is to specify a URL that we're going to Go out to and retrieve this box that we want to use as our base image. And that's that URL that I copy and pasted from the cloud images.ubuntu.com. So that's where that's gonna go. So that's gonna go and download that image and pull it in so that we can use it as our base image. Next I want to create basically a block of code where I'm going to provision this box and be able to run some command line commands in there via the shell. So I'm going to do a config.vm.provision. I'm going to provision this as shell, and this is going to be in line, and I'm going to specify the name here as shell. And then I'm gonna drop down here, and I can start to give those commands as I would as if I were in the box itself. So I'm gonna say pseudo, I want to use apt get because that's where I'm going to ultimately get the ceiling compiler, so I'm going to use assume yes. And I want to install ceiling and then once that's done I want to go ahead and get Swift. I want to be able to go out and get the appropriate version that I need. So I can go to download, and I'm going to go grab the URL associated with the version of Linux that I'm going to use. So I'll come in here and I'm simply going to use curl to do that. And so I will do just like that, so I want to go out and get this file, this is the file that's gonna be associated or the proper one. Associated with my version of Linux, then after that, I want to extract that because it's really just a compressed file here. So I'm going to copy this, I'll copy that, and I'll use tar, and I'm going to extract this like so, and then once it's extracted, I need to do a little bit of configuring, just like we saw over here previously on Swift.org. I'm going to need to export my path so that I can get access to it. So I'm simply going to do an echo. And I'm going to echo export, I'm gonna export path, and I need to specify the path to where this is gonna be found. And by default, it's gonna be at home slash vagrant slash, and then it's going to be in a directory called this here. Since that was the name of my file that I extracted, it will be in that directory. And then if you go back and take a look at the documentation here, it's gonna say that we need to export it with a slash user slash bin on the end, here. So it's slash user slash bin, and then we have a colon here. And then within double quotes, we're gonna have to escape this. We'll say dollar sign, path, and then we'll escape that again, so now we are doing exactly as we were told to within the documentation. And then I'm also going to add this little gem on the end here, so that it's just gonna make this accessible in our profile. So that I don't have to do that any more. And really, that's pretty much it. After that, I'm simply going to say, OK, I'm done with my shell here and then I can end my Vagrant.configure. And that's really it. So, I'm gonna go ahead and save that. And I want to save that within my desktop, within Swift Linux. And I need to save this as a very specially named file. Called Vagrant file, just like that. So let's go ahead and save it. And now I can go into my terminal, and if I go ahead and list that you can see I have a Vagrant file there, and the way that I get access to that is simply by saying Vagrant up. And by doing that, it's going to read through my configuration, and it's going to go out and get that image that I pointed it to at the vm.box configuration setting. It's gonna download that, it's going to go through the entire process of installing this, and it just so happens that I've already downloaded this before so it's already cached. If you haven't already downloaded it, then this might take some time, depending on your internet connection speed, but then it's gonna go through the process of issuing all those commands, installing that, and going on and on and on, and doing everything that I asked it to do. Now this may take some time, but once you get done you're gonna see that we should have finished the fruits of our labor. And as you can see here, we've gotten down to the very end, and hopefully here are done. So let's clear all this out, and what I want to do now is I want to see if this all worked. So in order to do that I need to get into my VM, and with Vagrant it's very simple. All we have to do is issue the Vagrant ssh command, and that will take us into our Vagrant instance. And as you can see here we're running a 121404. Everything seems to be up and running, and the only way for us to really know for sure if Swift is installed using the commands that we did is we're simply gonna type in Swift dash dash version, and if we've done it correctly we should see Swift version 2.2 dev with all of this little information here on the end of it. And that means we have actually made it. We've reached nirvana but not really yet. All we've done so far install it. In the next lesson I'm gonna show you some of the basic things that you have actually done by downloading and installing this and what you actually have access to and what you don't using Swift.