Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:7Length:39 minutes
  • Overview
  • Transcript

2.2 Clean Install of Swift on Linux

If you do have access to a physical machine running Linux and you want to try your hand and natively install support for it, then this lesson is for you. Getting Swift installed on your machine may be easier than you think.

2.2 Clean Install of Swift on Linux

In the previous lesson, I was able to show you how to use Vagrant to automate some of the steps in order to set up a Swift development environment on a VM. Now what if you were not using a VM and you wanted to do these steps manually. How would that look? And I'm going to show you that in this lesson now. So the first thing that I'm going to want to do is I'm going to pretend that I actually have a physical machine here. So I'm going to SSH in to my Vagrant again so that I can show you how this is going to look. Now I've already set this here, so if I were to hit Swift, it's going to take me into the ripple right away, but I'm not quite ready to do that because I want to show you what it would look like if that didn't exist or if I didn't have access to that. Now I installed everything under the context of the Vagrant user, but let's say I had a user on here that maybe didn't have access to it, and that's how I'm going to simulate not having Swift installed or not having access to those things. So the way that I'm gonna do that is I'm actually gonna switch over to a super user here. So within my Vagrant machine I've done that now, so as you can see, I'm running as root, so if I were to try to run Swift now, I don't have access to it. So let's go ahead and clear that out. So the first thing that I'm gonna need to do is I'm gonna need to go over to Swift.org to the download section and grab the appropriate url. So I'm going to copy the link address here, and I'm going to switch back over, and now what I want to do is I'm going to go to a directory here. I'm just going to go to another route here and I'm going to show you that there's nothing here right now. So what I want to do is I'm going to use wget. And I'll go ahead and paste that URL in and it's gonna go ahead and go out and download that particular file. Now remember this is a compressed file, and depending on your internet connection speed, this could take some time or it may be relatively quick. And here it seems to be going fairly quickly, so I should be done in just a few seconds. And when it's done downloading, I'm gonna need to unzip that. So as you can see now, I have my file here, but I need to unzip it. So let's go ahead and us tar and we're going to unzip this now. And I'm simply going to unzip it to that same location. So it's going to create a folder that's gonna have a similar name to this on this particular location on my machine. So let's go ahead and unzip that. And now once we've gotten down to the bottom here, I can show you that I now have a directory that contains everything I need for Swift to work on my machine. So I'm gonna need to export this, just like I did did before, export. And I'll set that equal to, or I'll actually export path and I'll set that equal to that directory that I just exported and then I'm going to do user bin/ Colon. And then after this, I'm going to use double quotes. And then I'm going to put in here Path, so I'm kind of appending all of this on there. So just like that. So this is what we're ultimately going to want to do. And once I've done that step, I'm going to be able to run Swift from here. And that's going to jump me into my. For some reason, something doesn't seem to be working correctly. You may not have c lane, the apple c compiler installed, but if you don't, you can simply use app get install c lane. It will go out and download that and install it with any dependencies, but right now, I seem to be just fine. So once I've done that, what can I do with Swift? Well, you can start at the very beginning and you can start to play around with the repel. Now, if you ever have done any sort of Swift development before, or you watched my previous course, then you'll know exactly what a rebel is. But just to show you a quick example, I can type in Swift and that's gonna take me into this Read, Execute, Print Loop and then, or Read, Evaluate, Print Loop. And within here I can do any sort of Swift commands I would like. I could do simple Print statements. I could print hello. And that'll work just fine. I could use this as a calculator. 23 plus six is going to be 29. I could do anything in here that I would like. I can import libraries and use functionality from those libraries. I could import g lib c, and from here, I can use the random function and generate random numbers and I can generate a number of them. And as you can see here, this is all working as you would expect, so you can play around within the REPL and that's great. But, at some point, you're probably gonna wanna be able to do some sort of development, some sort compilation to actually create like an executable. So let's see what something like that would look like. So let's go ahead and jump out of the REPL, and, in order to do that, we're gonna use the :q. It looks a little bit like kinda quitting from, say, vim, or something like that. So we'll jump out, clear. And now once we're out here, let's go ahead and create a simple Swift file that we can put some code into and actually have it execute or do something for us. So we'll just do something very simple now. And will simply can catenate into a file. And we'll just call this hello. And this is going to be very simple but it's just to prove a point. So we'll say hello.swift. And then within here we're simply going to print hello. This is a Swift app running on Linux. Just like that. So something very, very simple. So we'll hit Enter there and then we'll Ctrl+D to quit there and now you'll see that I have hello.swift. And to compile that, I'm simply going to use swift C, which is our compiler. So that will let us compile this hello.swift. And so as you can see now we have hello here. And now in order to execute that, I'll simply do /./hello. And we'll get hello this is a swift app running on Linux, so that's the basics of getting up and running. Now, in the next lesson I'll show you a little bit of how you can actually create a full application, including some dependencies using some cool tricks included in Swift.

Back to the top