Why Swift Is Not Just About Mobile Development
\nWhen you hear "Swift," the first association is iOS apps, Xcode, and the iPhone simulator. But over the last five years, the language has evolved into a full-fledged tool for server-side development. Vapor, Hummingbird, SwiftNIO — these are not just libraries, but an ecosystem capable of competing with Go and Rust. The problem is different: many developers write great backend code in Swift, but get stuck at the deployment stage. Sound familiar?
\nI've been through this journey myself: from "deploy to Heroku and forget it" to my own VPS with Docker and CI/CD. In this article, I'll tell you how to properly deploy Swift applications so they don't crash at 3 AM and users don't send angry emails. Spoiler: clouds aren't always a silver bullet, and a VPS can be more reliable than it seems.
\n\nWhat We Will Deploy: A Sample Vapor Application
\nFor clarity, let's take a typical REST API built with Vapor 4. It will be a simple server with one endpoint that returns JSON. The code is minimal but sufficient to demonstrate all stages of deployment.
\n\n// Sources/App/routes.swift\nimport Vapor\n\nfunc routes(_ app: Application) throws {\n app.get { req async in\n return "Hello, Swift on Server!"\n }\n \n app.get("api", "health") { req -> HTTPStatus in\n return .ok\n }\n}\n\nThis is all run via swift run or vapor run. But no one does that in production. We need a stable process: build, package, run, and monitor.
Option 1: VPS — An Old Friend Is Better Than Two New Ones
\nVirtual Private Server (VPS) is like having your own apartment: complete control, but also the responsibility for cleaning. For Swift, this is an ideal option if you want to understand how the system works under the hood.
\n\nHow to Prepare a VPS for Swift
\nTake Ubuntu 22.04 (or 24.04) on DigitalOcean, Hetzner, or Vscale. Swift officially supports Ubuntu, so there will be no issues.
\n\n- \n
- Connect via SSH:
ssh root@your-server-ip\n - Install dependencies:
apt update && apt install -y clang libicu-dev libcurl4-openssl-dev libssl-dev\n - Download Swift 5.9+ from swift.org and extract it to
/usr/local\n
# Example of installing Swift on Ubuntu\nwget https://download.swift.org/swift-5.9.2-release/ubuntu2204/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu22.04.tar.gz\ntar xzf swift-5.9.2-RELEASE-ubuntu22.04.tar.gz\nmv swift-5.9.2-RELEASE-ubuntu22.04 /usr/local/swift\necho 'export PATH=/usr/local/swift/usr/bin:$PATH' >> ~/.bashrc\nsource ~/.bashrc\nswift --version\n\nDeployment via Git + systemd
\nThe simplest way: clone the repository onto the server, build the binary, and run it as a service.
\n\n# On the server\ngit clone https://github.com/yourname/your-swift-app.git\ncd your-swift-app\nswift build -c release\ncp .build/release/Run /usr/local/bin/myapp\n\n# Create a systemd unit\nsudo nano /etc/systemd/system/myapp.service\n\n[Unit]\nDescription=My Swift App\nAfter=network.target\n\n[Service]\nExecStart=/usr/local/bin/myapp\nWorkingDirectory=/root/your-swift-app\nRestart=always\nUser=root\nEnvironment="PORT=8080"\n\n[Install]\nWantedBy=multi-user.target\n\nStart it: systemctl enable myapp && systemctl start myapp. Done! Now your application runs as a daemon and restarts if it crashes.
Pros of VPS: full control, low cost ($5–10/month), you can install any utilities. Cons: you need to set up monitoring, updates, and security yourself. If your application grows, you'll have to scale it manually.
\n\nOption 2: Docker — Containerizing Swift
\nDocker solves the "it works on my machine" problem. You package the application together with its environment and dep