Requirements in order to complete this tutorial:
If you do not have at least Xcode 9.3, you cannot run Vapor 3, as Vapor 3 requires Swift 4.1, which is only available on Xcode 9.3.
There is a much more detailed and comprehensive article about the differences, here
First, let's install Homebrew. Simply run the following command in terminal:
Note: If you already have Vapor 2 (or Vapor 3 beta) installed on your machine, simply run
$ brew vapor update, and you can skip the steps below.
Step 2: Add Homebrew Tap Next, we need to give Homebrew access to Vapors MacOS packages. To do so, simply run:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew tap vapor/homebrew-tap
Step 3: Installing Vapor. Run the following command:
$ brew update
$ brew install vapor
After installation is complete, you can test to make sure everything is installed correctly. Run:
$ vapor --version
And the output should say:
Vapor Toolbox: 3.1.7 Vapor Framework: 3.0.0
Great! Vapor is now installed, and we are ready to create our first project.
Before we proceed, run the following in terminal:
$ vapor --help
You should see the following come up:
Here we see a list of commands that we can use with Vapor's CLI (command line interface).
We won't be using all of these, but to start, I'll just point out a few of the common ones that you will need to use on a regular basis:
vapor updateand 2) run
vapor Xcodeto regenerate the Xcode project.
Time to create your first Vapor project! In terminal, run:
$ vapor new HelloWorld
This may take a few moments. Upon completion, you should see:
Great! As it says, now run
$ cd HelloWorld to enter into our project directory.
Once in your project directory, we need to generate an Xcode Project. Run:
$ vapor xcode
This may take a few moments as well. Upon completion, you will see:
Generating Xcode Project [Done] Select the Run scheme to run. Open Xcode project? y/n>
Respond with `y` to open it, and then press Enter. When opening the project, you should see this:
To run our project, we must change one thing. Click where it says "HelloWorld-Package" at the top:
And scroll down to where it says "Run", and select that:
It should now look like:
Now run the project by clicking the Play button at the top left, and navigate to
http://localhost:8080/hello. You should see:
And that's your first Vapor project! There is much, much more to learn with Vapor as well. There will be plenty of tutorials to come in the near future.
Thanks for reading!