Swift 6.0.3 (Ubuntu 24.04) AMI Administrator Guide
1. Quick Start Information
Connection Methods:
- Access the instance via SSH using the
ubuntuuser. Usesudoto run commands requiring root privileges. To switch to the root user, usesudo su - root.
Install Information:
- OS: Ubuntu 24.04 LTS
- Swift version: 6.0.3 (swift-6.0.3-RELEASE)
- Target architecture: x86_64-unknown-linux-gnu
- Swift Install Directory:
/usr/share/swift - Swift Binary Path:
/usr/share/swift/usr/bin/swift - Environment Configuration:
/etc/profile.d/swift.sh
Quick Verification Commands:
- Check Swift version:
swift --version - Verify Swift location:
which swift - Run Swift REPL:
swift repl(interactive mode) - Compile Swift file:
swift build - Run Swift script:
swift run
Development Tools Included:
- Swift Compiler:
swift(v6.0.3) - Swift Package Manager:
swift package - Swift Build System:
swift build - Swift REPL:
swift repl(interactive shell) - Clang Compiler: Required for linking
- Python 3 Development Libraries: For Swift-Python interop
Firewall Configuration:
- Please allow SSH port 22.
- For security, it is recommended to limit SSH access to trusted IPs only.
2. First Launch & Verification
Step 1: Connect to Your Instance
- Launch your instance in your cloud provider's console (e.g., AWS EC2)
- Ensure SSH port 22 is allowed in your security group
- Connect via SSH:
ssh -i your-key.pem ubuntu@YOUR_PUBLIC_IP
Step 2: Verify Swift Installation
Check the Swift version:
swift --version
Expected Output:
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu
Verify the installation path:
which swift
Expected Output:
/usr/share/swift/usr/bin/swift
Step 3: Test Swift Compiler
Create and run a simple Swift program:
# Create a test file
echo 'print("Hello, Server-Side Swift!")' > hello.swift
# Run the script
swift hello.swift
# Clean up
rm hello.swift
Expected Output:
Hello, Server-Side Swift!
How This Works:
swift hello.swift: Compiles and executes the Swift file in one step- The Swift compiler automatically links against Clang and system libraries
- No separate compilation step needed for simple scripts
Step 4: Test Swift Package Manager
Initialize a sample Swift package:
# Create a new directory
mkdir swift-test && cd swift-test
# Initialize a new Swift package
swift package init --type executable
# Build the package
swift build
# Run the executable
./.build/debug/swift-test
Expected Output:
Hello, world!
How This Works:
swift package init: Creates a standard Swift package structure with Package.swift manifestswift build: Compiles the package and its dependencies- The executable is placed in
.build/debug/directory
3. Architecture & Detailed Configuration
This AMI uses the official Swift.org binary distribution for Ubuntu 24.04, ensuring compatibility with the latest Swift ecosystem and server-side frameworks like Vapor and Kitura.
Installation Architecture:
[Swift.org Download]
↓
[swift-6.0.3-RELEASE-ubuntu24.04.tar.gz]
↓
[Extract to /usr/share/swift]
↓
├── /usr/share/swift/usr/bin/swift → Swift compiler
├── /usr/share/swift/usr/bin/swiftc → Swift compiler (explicit)
├── /usr/share/swift/usr/bin/swift-package → Package manager
└── /usr/share/swift/usr/lib/ → Swift standard library
↓
[Environment Configuration]
↓
/etc/profile.d/swift.sh → Adds Swift to PATH
↓
[System Dependencies]
↓
├── Clang → Linker and C/C++ interop
├── libpython3-dev → Swift-Python interop
├── libcurl4 → Network operations
└── libstdc++-13-dev → C++ standard library
Key Design Decisions:
- Installation Location:
/usr/share/swiftis the standard location for third-party software on Linux - Official Binary: Using Swift.org official builds ensures compatibility with SwiftPM ecosystem
- System-Wide Installation: All users can access Swift without per-user configuration
- Dependency Isolation: System dependencies installed via apt ensure reproducibility
3.1. Environment Configuration File
File Location: /etc/profile.d/swift.sh
File Content:
# Swift 环境变量
export PATH=/usr/share/swift/usr/bin:"${PATH}"
How This Works:
- This file is automatically sourced by the shell for all users
- Prepends Swift's binary directory to the PATH
- Ensures
swiftcommand is available system-wide
3.2. System Dependencies
Required Packages:
Swift requires several system libraries for compilation and runtime:
-
Compiler Toolchain:
clang: LLVM-based C/C++ compiler (Swift uses Clang for linking)binutils: Binary utilities (linker, assembler)libc6-dev: C standard library development files
-
Language Interoperability:
libpython3-dev: Python 3 development headers (Swift-Python interop)libstdc++-13-dev: C++ standard library (required for some Swift features)
-
Network and Data:
libcurl4-openssl-dev: HTTP client librarylibxml2-dev: XML parsing librarylibsqlite3-0: SQLite database library
-
Build Tools:
git: Version control (required by Swift Package Manager)pkg-config: Package configuration toolunzip: Archive extraction
4. How-To-Create: Reproduce This Environment
This section explains how this AMI was built, allowing you to reproduce the installation on any Ubuntu 24.04 system.
Step 1: Install System Dependencies
Purpose: Install all required libraries and tools that Swift compiler depends on.
# Update package index
sudo apt-get update
# Install Swift runtime dependencies
sudo apt-get install -y \
binutils \
git \
gnupg2 \
libc6-dev \
libcurl4-openssl-dev \
libedit2 \
libgcc-s1 \
libpython3-dev \
libsqlite3-0 \
libstdc++-13-dev \
libxml2-dev \
zlib1g-dev \
pkg-config \
tzdata \
unzip \
clang
How This Works:
clang: Swift uses Clang as its linker backend. Without it, you'll geterror: link command failedlibpython3-dev: Enables Swift-Python interoperability (calling Python from Swift)libcurl4-openssl-dev: Required for networking in Swift (URLSession, HTTP clients)libstdc++-13-dev: C++ standard library headers (Swift uses C++ internally)zlib1g-dev: Compression library (used by Swift Package Manager)
Why These Dependencies?
Swift is not a standalone compiler. It leverages:
- Clang for C/C++ interop and linking
- System libraries for networking, compression, and data parsing
- Python integration for scripting use cases
Step 2: Download Swift Official Binary
Purpose: Download the pre-compiled Swift toolchain from Swift.org for Ubuntu 24.04.
# Define version variables (makes upgrades easier)
SWIFT_VERSION=6.0
SWIFT_PLATFORM=ubuntu24.04
SWIFT_BRANCH=swift-${SWIFT_VERSION}-release
SWIFT_TAG=swift-${SWIFT_VERSION}-RELEASE
# Download official tar.gz package
wget https://download.swift.org/${SWIFT_BRANCH}/${SWIFT_PLATFORM}/${SWIFT_TAG}/${SWIFT_TAG}-${SWIFT_PLATFORM}.tar.gz
How This Works:
SWIFT_VERSION=6.0: Locks the major/minor versionSWIFT_PLATFORM=ubuntu24.04: Ensures we get the Ubuntu 24.04-compatible buildSWIFT_BRANCH: Points to the release branch on Swift.org's download serverSWIFT_TAG: The exact release tag (e.g., swift-6.0-RELEASE)
URL Structure:
Swift.org uses a consistent URL pattern:
https://download.swift.org/
└── {branch}/ (e.g., swift-6.0-release)
└── {platform}/ (e.g., ubuntu24.04)
└── {tag}/ (e.g., swift-6.0-RELEASE)
└── {tag}-{platform}.tar.gz
Actual Download URL (for reference):
https://download.swift.org/swift-6.0-release/ubuntu24.04/swift-6.0-RELEASE/swift-6.0-RELEASE-ubuntu24.04.tar.gz
Step 3: Install Swift Globally
Purpose: Extract Swift to a system-wide location and set proper permissions.
# Create installation directory
sudo mkdir -p /usr/share/swift
# Extract archive to installation directory
# --strip-components=1 removes the outer folder, placing contents directly in /usr/share/swift
sudo tar xz -C /usr/share/swift --strip-components=1 -f ${SWIFT_TAG}-${SWIFT_PLATFORM}.tar.gz
# Set proper permissions (readable by all users)
sudo chmod -R 755 /usr/share/swift
How This Works:
/usr/share/swift: Standard Linux location for third-party software--strip-components=1: The downloaded archive has a top-level directory (e.g.,swift-6.0-RELEASE-ubuntu24.04/). This flag removes it, so contents go directly into/usr/share/swiftchmod -R 755: Ensures all users can read and execute Swift binaries
Directory Structure After Extraction:
/usr/share/swift/
├── usr/
│ ├── bin/
│ │ ├── swift # Main compiler/REPL
│ │ ├── swiftc # Explicit compiler invocation
│ │ ├── swift-package # Package manager
│ │ └── swift-build # Build system
│ ├── lib/
│ │ └── swift/ # Standard library
│ └── include/
│ └── swift/ # Header files
└── README.md
Step 4: Configure Environment Variables
Purpose: Make the swift command available system-wide for all users.
# Create environment configuration file
sudo tee /etc/profile.d/swift.sh > /dev/null << 'EOF'
# Swift 环境变量
export PATH=/usr/share/swift/usr/bin:"${PATH}"
EOF
# Make the file executable
sudo chmod +x /etc/profile.d/swift.sh
# Load the configuration immediately (for current session)
source /etc/profile.d/swift.sh
How This Works:
/etc/profile.d/swift.sh: This directory contains shell scripts that are automatically executed when users log inexport PATH=...: Prepends Swift's binary directory to the PATH environment variablesource /etc/profile.d/swift.sh: Applies the changes to the current shell session (new sessions will load it automatically)
Why /etc/profile.d/?
- Files in this directory are sourced by
/etc/profileduring login - Applies to all users system-wide
- Survives system reboots and updates
Step 5: Verification and Cleanup
Purpose: Confirm Swift is working correctly and remove installation artifacts to reduce AMI size.
# Verify Swift version
swift --version
# Expected: Swift version 6.0.3 (swift-6.0.3-RELEASE)
# Verify Swift path
which swift
# Expected: /usr/share/swift/usr/bin/swift
# Test Swift compiler
echo 'print("Hello, Server-Side Swift!")' > hello.swift
swift hello.swift
# Expected: Hello, Server-Side Swift!
rm hello.swift
# Clean up downloaded archive (600+ MB)
rm ${SWIFT_TAG}-${SWIFT_PLATFORM}.tar.gz
# Clear command history (for AMI creation)
history -c
Cleanup Results:
- Removes ~600 MB tar.gz archive
- Clears shell history (removes sensitive commands for AMI snapshots)
- Final AMI size: ~1.2 GB (Swift installation only)
5. Using the Swift Environment
5.1. Swift REPL (Interactive Shell)
Start the REPL:
swift repl
Example Session:
Welcome to Swift version 6.0.3 (swift-6.0.3-RELEASE).
Type :help for assistance.
1> let greeting = "Hello, Swift!"
greeting: String = "Hello, Swift!"
2> print(greeting)
Hello, Swift!
3> let numbers = [1, 2, 3, 4, 5]
numbers: [Int] = 5 values {
[0] = 1
[1] = 2
[2] = 3
[3] = 4
[4] = 5
}
4> :quit
REPL Commands:
:help- Show available commands:quit- Exit the REPL:type <expression>- Print the type of an expression
5.2. Running Swift Scripts
Create a Script:
cat > server.swift << 'EOF'
import Foundation
print("Starting server...")
print("Current time: \(Date())")
print("Server running on port 8080")
EOF
Execute the Script:
swift server.swift
Expected Output:
Starting server...
Current time: 2026-02-13 12:00:00 +0000
Server running on port 8080
5.3. Creating a Swift Package
Initialize a New Package:
# Create project directory
mkdir my-swift-project
cd my-swift-project
# Initialize as executable package
swift package init --type executable
# Project structure created:
# ├── Package.swift
# ├── Sources/
# │ └── my-swift-project/
# │ └── main.swift
# └── Tests/
# └── my-swift-projectTests/
Package.swift (Generated):
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "my-swift-project",
targets: [
.executableTarget(
name: "my-swift-project"
),
]
)
Build and Run:
# Build the package
swift build
# Run the executable
swift run
Expected Output:
Hello, world!
5.4. Building a Web Server with Vapor
Vapor is the most popular Swift web framework for server-side development.
Create a Vapor Project:
# Create new directory
mkdir vapor-app && cd vapor-app
# Initialize Vapor package
cat > Package.swift << 'EOF'
// swift-tools-version:6.0
import PackageDescription
let package = Package(
name: "vapor-app",
platforms: [
.macOS(.v13)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.89.0"),
],
targets: [
.executableTarget(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
]
),
]
)
EOF
# Create Sources directory
mkdir -p Sources/App
cat > Sources/App/main.swift << 'EOF'
import Vapor
var env = try Environment.detect()
let app = Application(env)
defer { app.shutdown() }
app.get("hello") { req in
return "Hello, Vapor!"
}
try app.run()
EOF
# Build and run (first build will download dependencies)
swift build
swift run App
Access the Server:
# In another terminal
curl http://localhost:8080/hello
# Output: Hello, Vapor!
5.5. Compiling for Release
Build Optimized Binary:
# Build with release configuration
swift build -c release
# Binary location
ls -lh .build/release/
Release vs Debug:
| Mode | Optimization | Size | Speed | Debug Info |
|---|---|---|---|---|
| Debug | -Onone | ~10 MB | 1x | Yes |
| Release | -O | ~2 MB | 5-10x | No |
6. Important File Locations
| File Path | Purpose |
|---|---|
/usr/share/swift/ | Swift installation root directory |
/usr/share/swift/usr/bin/swift | Swift compiler and REPL |
/usr/share/swift/usr/bin/swiftc | Swift compiler (explicit invocation) |
/usr/share/swift/usr/bin/swift-package | Swift Package Manager |
/usr/share/swift/usr/lib/swift/ | Swift standard library |
/etc/profile.d/swift.sh | Environment configuration (adds Swift to PATH) |
~/.swiftpm/ | User-specific Swift Package Manager cache |
.build/ | Build output directory (in project) |
Package.swift | Swift package manifest file |
7. Troubleshooting
Issue 1: Command Not Found: swift
Symptoms:
$ swift --version
-bash: swift: command not found
Diagnosis:
Check if Swift is installed:
ls -la /usr/share/swift/usr/bin/swift
Solution:
Reload environment configuration:
source /etc/profile.d/swift.sh
Or log out and log back in:
exit
ssh -i your-key.pem ubuntu@YOUR_PUBLIC_IP
Verify:
echo $PATH | grep swift
# Should show: /usr/share/swift/usr/bin
Issue 2: Link Command Failed
Symptoms:
$ swift build
error: link command failed with exit code 1 (use -v to see invocation)
ld: cannot find -lc++
Diagnosis:
Missing Clang or C++ standard library.
Solution:
Install required dependencies:
sudo apt-get update
sudo apt-get install -y clang libstdc++-13-dev
Verify:
which clang
# Output: /usr/bin/clang
swift --version
# Should show Swift version without errors
Issue 3: Swift Package Manager Hangs
Symptoms:
$ swift build
Fetching https://github.com/vapor/vapor.git
[Hangs indefinitely...]
Diagnosis:
Network connectivity issue or DNS resolution problem.
Solution:
Test network connectivity:
# Test GitHub access
curl -I https://github.com
# Check DNS resolution
nslookup github.com
If GitHub is blocked, use a mirror or configure proxy:
# Configure git proxy (if needed)
git config --global http.proxy http://your-proxy:port
Alternative:
Use package cache if available:
# Clean and retry
rm -rf .build
swift package reset
swift build
Issue 4: Segmentation Fault During Compilation
Symptoms:
$ swift build
Segmentation fault (core dumped)
Diagnosis:
Insufficient memory or corrupted Swift installation.
Solution 1: Check Memory:
free -h
# Ensure at least 2 GB free memory
Solution 2: Reinstall Swift:
sudo rm -rf /usr/share/swift
# Re-run installation steps from Section 4
Solution 3: Reduce Compilation Parallelism:
swift build --jobs 1
Issue 5: Package Dependency Resolution Failed
Symptoms:
$ swift build
error: package at 'https://github.com/vapor/vapor.git' is using Swift tools version 5.9.0 but the installed version is 6.0.3
Diagnosis:
Package requires older Swift version.
Solution:
Update package to use Swift 6.0:
Edit Package.swift:
// Change this line:
// swift-tools-version:5.9
// To:
// swift-tools-version:6.0
Or use compatible package version:
# Check package releases
git ls-remote --tags https://github.com/vapor/vapor.git
# Use specific version
.package(url: "https://github.com/vapor/vapor.git", .exact("4.89.0"))
Issue 6: Permission Denied Errors
Symptoms:
$ swift build
error: unable to create directory: Permission denied
Diagnosis:
Insufficient permissions in project directory.
Solution:
Ensure you own the project directory:
# Check ownership
ls -la
# Fix ownership if needed
sudo chown -R ubuntu:ubuntu ~/my-swift-project
Verify:
cd ~/my-swift-project
swift build
# Should work without sudo
8. Final Notes
Key Takeaways
- Swift 6.0.3 is installed system-wide at
/usr/share/swift - Clang is required for linking Swift binaries
- Swift Package Manager handles dependencies automatically
- All tools are verified and tested on Ubuntu 24.04 LTS
- The installation is production-ready and AMI-optimized
Server-Side Swift Use Cases
- High-Performance APIs: Vapor, Kitura frameworks
- Microservices: Docker + Swift for cloud-native apps
- CLI Tools: Swift Package Manager for command-line utilities
- AWS Lambda: Swift runtime for serverless functions
- Real-Time Services: WebSocket servers, chat applications
Additional Resources
- Official Swift Documentation: https://swift.org/documentation/
- Swift Book (Free): https://docs.swift.org/swift-book/
- Vapor Framework: https://vapor.codes
- Swift Package Index: https://swiftpackageindex.com/
- Swift Forums: https://forums.swift.org/
Support
If you encounter issues not covered in this guide:
- Check the troubleshooting section above
- Review Swift.org official documentation
- Verify your security group and firewall settings
- Check system logs:
sudo journalctl -xe - Visit Swift Forums for community support
For support or questions, please contact the Easycloud team.