Swift Tutorial · Swift Basics · Lesson 2 of 30

Swift Get Started

Install Swift with Xcode or the swift.org toolchain, create a package, and build and run it.

Create a free account to save this page, take notes and track your progress. Sign in

Install

  • macOS: install Xcode from the App Store; it includes Swift, the iOS SDKs and simulators.
  • Linux and Windows: install the toolchain from swift.org/install (the swiftly installer manages versions).
swift --version

Swift Package Manager

mkdir Hello && cd Hello
swift package init --type executable   # Package.swift and Sources/main.swift
swift run                              # build and run
swift build -c release                 # optimised build
swift test                             # run tests

Sources/main.swift starts as:

Example 1
print("Hello from my first Swift package!")

Output

Hello from my first Swift package!

Run this on your computer — see “Get Started” for setup.

iOS and macOS apps are created in Xcode (File > New > Project), which uses the same Swift language with Apple's frameworks such as SwiftUI.

Test yourself

Which command builds and runs a Swift package?

  1. swiftc start
  2. swift run
  3. xcode run
  4. swift package go
Show answer

Answer: swift run

Was this page helpful?