How To Install Swift Programming Language on Fedora 43

Swift programming language has evolved far beyond its Apple ecosystem origins. Today, developers can harness Swift’s power on Linux systems, opening doors to server-side development, command-line utilities, and cross-platform applications. Fedora 43, with its cutting-edge packages and robust development tools, provides an excellent environment for Swift programming.
This comprehensive guide walks you through installing Swift on Fedora 43 using two proven methods. Whether you’re a seasoned developer exploring new platforms or a beginner diving into system programming, you’ll find everything needed to get Swift running smoothly on your Fedora machine.
Understanding Swift on Fedora 43
What Makes Swift Special?
Swift stands out as a high-performance, compiled programming language designed with memory safety at its core. The language combines modern syntax with powerful features that prevent common programming errors before they become runtime crashes. Originally developed by Apple for iOS and macOS development, Swift became open-source in 2015, allowing the community to bring it to Linux platforms.
The language excels at system programming while remaining approachable for beginners. Its type inference, optional handling, and protocol-oriented design create code that’s both safe and expressive.
Swift’s Place in the Fedora Ecosystem
Fedora has embraced Swift since version 28, integrating the language into official repositories. This integration means Fedora users can install Swift through standard package management tools, receiving updates alongside their system packages. The distribution’s commitment to Swift demonstrates the language’s growing importance in Linux development circles.
Developers choose Swift on Fedora for building server-side applications, automation scripts, and even contributing to Swift’s own development. The combination offers stability, modern tooling, and active community support.
Prerequisites and System Requirements
Hardware and Software Needs
Before diving into installation, verify your system meets these requirements:
- Fedora 43 Workstation or Server edition (fully updated)
- Minimum 4 GB RAM (8 GB recommended for comfortable development)
- At least 5 GB free disk space for Swift and dependencies
- x86_64 or aarch64 processor architecture
- Active internet connection for downloading packages
Swift compiles code into native machine instructions, so adequate RAM and disk space ensure smooth compilation of larger projects. Check your available space with df -h before proceeding.
Preparing Your System
Open your terminal application. Update your system to ensure compatibility with the latest packages:
sudo dnf upgrade --refresh
This command refreshes repository metadata and upgrades all installed packages. Wait for the process to complete. System updates prevent conflicts between Swift dependencies and existing software.
Verify your system architecture matches Swift’s requirements:
uname -m
You should see x86_64 or aarch64. These architectures have full Swift support on Fedora.
If you plan to use Swift Package Manager for managing dependencies, install Git:
sudo dnf install git
Git integration allows Swift’s package manager to fetch and manage external libraries seamlessly.
Installation Method 1: Using DNF Package Manager (Recommended)
Why Choose the DNF Method?
DNF represents the straightforward path for most Fedora users. This method integrates Swift into your system’s package management infrastructure, providing automatic security updates and simplified maintenance. The Fedora-packaged version undergoes distribution testing, ensuring compatibility with your system’s libraries and tools.
Security patches arrive through your regular system updates. No additional configuration or manual downloads required.
Step-by-Step DNF Installation
Step 1: Refresh Package Database
Even if you updated earlier, refresh your package database specifically before installing Swift:
sudo dnf upgrade --refresh
Fresh metadata ensures you download the latest available Swift version from Fedora repositories.
Step 2: Install the Swift Language Package
Execute the installation command:
sudo dnf install swift-lang
DNF displays the package size and required dependencies. Swift pulls in several development libraries including GCC tools, GNU C Library development files, and Python support. The download reaches approximately 650 MB, expanding to roughly 3 GB installed.
Press y when prompted to confirm installation. The process takes several minutes depending on your connection speed and system performance.
Watch as DNF resolves dependencies automatically. The package manager ensures all required libraries install correctly without manual intervention.
Step 3: Verify Successful Installation
Once installation completes, verify Swift works correctly:
swift --version
You’ll see output displaying the Swift version (typically 6.x series), target architecture, and build configuration. This confirms the compiler installed successfully and recognizes your system environment.
Example output looks like:
Swift version 6.0 (swift-6.0-RELEASE)
Target: x86_64-unknown-linux-gnu
The version number may vary depending on when you install and which version Fedora packages.
What DNF Installs
The swift-lang package includes everything needed for Swift development:
- Swift Compiler (swiftc): Transforms Swift source code into executable binaries
- Swift REPL: Interactive environment for testing code snippets
- Standard Library: Core Swift functionality and types
- Swift Package Manager: Dependency management and build system
- Runtime Libraries: Necessary components for running Swift programs
Files install to /usr/libexec/swift with executables linked in your PATH.
Installation Method 2: Using Swiftly Toolchain Manager (Alternative)
When Swiftly Makes Sense
Swiftly offers advantages for specific use cases. Choose this method when you need the absolute latest Swift releases from swift.org before they reach Fedora repositories. Developers working on Swift itself or testing cutting-edge features benefit from Swiftly’s flexibility.
The tool excels at managing multiple Swift versions simultaneously, letting you switch between releases for compatibility testing.
Installing Swift with Swiftly
Step 1: Download and Extract Swiftly
Download the Swiftly installer for your architecture:
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz
The $(uname -m) automatically inserts your architecture, downloading the correct version.
Extract the downloaded archive:
tar zxf swiftly-$(uname -m).tar.gz
This creates a swiftly executable in your current directory.
Step 2: Initialize Swiftly
Run the initialization script:
./swiftly init
Swiftly creates directories under ~/.local/share/swiftly/ and modifies your shell profile to include Swift in your PATH. The initialization process downloads and installs the latest stable Swift release automatically.
Step 3: Load Your Environment
Activate the new environment variables:
source "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh"
Alternatively, log out and log back in. Your shell profile loads automatically on new sessions.
Verify installation:
swift --version
You should see the latest Swift version from swift.org.
Managing Multiple Versions with Swiftly
Install additional Swift versions:
swiftly install 5.10
Switch between installed versions:
swiftly use 5.10
This flexibility helps test code across Swift releases, ensuring compatibility.
Swiftly Limitations
Swiftly requires specific CPU instructions that older processors might lack. Docker containers sometimes encounter compatibility issues with Swiftly. If you experience “Illegal instruction” errors, fall back to the DNF method for better compatibility.
Post-Installation Verification and Testing
Confirm All Components Work
Check Swift’s installation location:
which swift
which swiftc
These commands show where Swift executables reside in your filesystem. DNF installs typically show /usr/bin/swift, while Swiftly uses paths under your home directory.
Explore Available Tools
List Swift’s subcommands:
swift --help
You’ll see options for build, package, run, test, and repl. Each subcommand serves specific development tasks. The help output provides a quick reference for available functionality.
Access detailed manual pages:
man swift
Manual pages offer comprehensive documentation for command-line options and usage patterns.
Creating and Running Your First Swift Program
Interactive Programming with REPL
Swift’s REPL (Read-Eval-Print Loop) provides an interactive environment perfect for experimentation. Launch it:
swift repl
Or simply:
swift
The REPL prompt appears, ready for input. Try basic operations:
let greeting = "Hello, Fedora!"
print(greeting)
The REPL evaluates each line immediately, displaying results. Test arithmetic:
let result = 42 * 2
REPL shows the calculated value instantly. This immediate feedback accelerates learning and debugging.
Exit REPL by typing :q or pressing Ctrl + D.
REPL shines for quick calculations, testing API behavior, and learning Swift syntax without creating files.
Writing Swift Scripts
Create a simple Swift file:
echo 'print("Hello, World!")' > hello.swift
Swift files use the .swift extension. Run the script directly:
swift hello.swift
Swift executes the code immediately without explicit compilation. This interpreted mode works perfectly for scripts and rapid prototyping.
Compiling Standalone Programs
Transform your script into a compiled executable:
swiftc hello.swift -o hello
The compiler (swiftc) generates a binary named hello. Run your compiled program:
./hello
Compiled binaries run faster than interpreted scripts. They’re ideal for production applications and tools you’ll use repeatedly.
Create more complex programs by editing hello.swift with your preferred text editor:
func greet(name: String) {
print("Welcome to Swift on Fedora, \(name)!")
}
greet(name: "Developer")
Compile and run again to see your function in action.
Working with Swift Package Manager
Understanding Swift’s Build System
Swift Package Manager (SPM) handles dependency management and project building. It integrates seamlessly with the Swift toolchain, eliminating the need for external build tools.
Creating Your First Package
Initialize a new Swift package:
swift package init
SPM creates a project structure:
Package.swift: Manifest defining package metadata and dependenciesSources/: Directory containing source codeTests/: Directory for unit tests
The Package.swift manifest uses Swift syntax to describe your package:
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "MyProject",
targets: [
.executableTarget(
name: "MyProject"
),
]
)
This structure supports projects from simple scripts to complex applications.
Building and Running Packages
Build your package:
swift build
SPM compiles source code and places executables in .build/debug/. The build system handles dependency resolution automatically.
Run your package directly:
swift run
This command builds if necessary and executes your program. No need to navigate into build directories.
Testing Your Code
Swift Package Manager includes testing support. Run tests:
swift test
Tests ensure your code works correctly as you develop. Write tests in the Tests directory following Swift’s XCTest framework conventions.
Adding Dependencies
Edit Package.swift to include external libraries. SPM downloads and builds dependencies automatically, streamlining development.
Managing Swift on Fedora 43
Keeping Swift Updated
With DNF
Your Swift installation updates alongside system packages:
sudo dnf upgrade --refresh
Fedora handles Swift updates through the standard package management pipeline. Security patches arrive automatically through regular system maintenance.
Check specifically for Swift updates:
dnf check-update swift-lang
With Swiftly
Update Swiftly itself:
swiftly self-update
Check for new Swift toolchain releases:
swiftly update
Swiftly automatically downloads and installs the latest stable Swift version.
Removing Swift
Uninstalling DNF Version
Remove the package:
sudo dnf remove swift-lang
Clean up orphaned dependencies:
sudo dnf autoremove
This removes Swift and any dependencies no longer needed by other software.
Uninstalling Swiftly
Remove all toolchains:
swiftly uninstall all
Remove Swiftly itself:
swiftly self-uninstall
Manually clean shell profile modifications if desired.
Troubleshooting Common Issues
Installation Problems
Repository Connection Errors: Check your internet connection and try again. Fedora’s mirrors occasionally experience high load.
Insufficient Disk Space: Swift requires substantial space. Clear unnecessary files or use a larger partition.
Dependency Conflicts: Update your system completely before installing Swift. Outdated packages sometimes conflict with Swift’s requirements.
Swift Package Manager Issues
Some users report package resolution errors on Fedora 43. If swift package resolve fails, ensure Git is installed and configured properly. Check that your package manifest uses compatible syntax for your Swift version.
Build errors often stem from missing development libraries. Install the development tools group:
sudo dnf groupinstall "Development Tools"
REPL and Compiler Problems
Command Not Found: Verify your PATH includes Swift’s installation directory. For DNF installations, this should be automatic. For Swiftly, ensure you sourced the environment script.
Illegal Instruction Errors: Swiftly requires modern CPU instruction sets. Switch to the DNF method if you encounter these errors.
Memory Issues During Compilation: Large projects need adequate RAM. Close unnecessary applications or add swap space.
Congratulations! You have successfully installed Swift. Thanks for using this tutorial for installing the Swift Programming Language on Fedora 43 system. For additional help or useful information, we recommend you check the official Swift website.