RHEL BasedRocky Linux

How To Install Swift Programming Language on Rocky Linux 10

Install Swift Programming Language on Rocky Linux 10

Swift has come a long way from being an Apple-exclusive language. Today, it powers server-side APIs, command-line tools, microservices, and serverless functions on Linux — and Rocky Linux 10 is one of the most solid platforms to run it on. Whether you are a developer expanding beyond macOS or a sysadmin adding a modern compiled language to your server stack, this guide walks you through everything you need. You will learn how to install Swift on Rocky Linux 10 using three methods, verify the installation, write your first program, and troubleshoot common errors along the way.

What Is Swift and Why Does It Matter on Linux?

Swift is a general-purpose, compiled programming language originally developed by Apple and open-sourced in December 2015. It was built from the ground up with a modern approach to safety, performance, and expressive software design patterns. What makes Swift compelling on Linux is its combination of speed and safety — the compiler catches most bugs before the program even runs.

Since its open-source release, Swift has evolved into a cross-platform language with strong Linux support managed at swift.org. The Swift toolchain on Linux includes the compiler (swiftc), an interactive REPL, and the built-in Swift Package Manager (SPM) — no Xcode required. Real-world benchmarks showed Swift running server-side workloads faster than Python at a fraction of the operating cost. That kind of performance profile makes it an attractive choice for backend engineers and infrastructure teams alike.

Popular use cases on Linux include building web APIs with the Vapor and Hummingbird frameworks, writing fast CLI automation tools, deploying AWS Lambda functions, and running lightweight microservices in Podman or Docker containers.

Why Rocky Linux 10 Is a Great Host Platform

Rocky Linux 10 is a production-ready, enterprise-grade Linux distribution that is 100% binary-compatible with Red Hat Enterprise Linux (RHEL). It was officially released in June 2025 and ships with an updated package ecosystem including Python 3.12, refreshed GCC toolchains, and improved security primitives like Post-Quantum Cryptography support and yescrypt password hashing. These modernized system libraries align well with Swift’s runtime dependencies, reducing friction during installation.

Rocky Linux 10 also dropped 32-bit package support entirely, meaning every workload runs natively on 64-bit architecture — exactly what Swift’s compiler targets. For teams running Swift-powered services in production, Rocky Linux 10 offers long-term support, SELinux enforcement, and enterprise stability without licensing costs.

Prerequisites and System Requirements

Before diving in, make sure your setup meets the following requirements:

  • Operating System: Rocky Linux 10 (x86_64 or aarch64 architecture)
  • User Access: A non-root user with sudo privileges, or direct root access
  • RAM: At least 2 GB — the Swift compiler is memory-intensive during builds
  • Disk Space: Minimum 2 GB of free space; the swift-lang package alone is roughly 377 MB compressed
  • Network: Active internet connection for downloading packages and toolchains
  • Pre-installed Tools: curl, tar, and dnf — all available by default on Rocky Linux 10

To confirm your system architecture before downloading any binaries, run:

uname -m

You should see either x86_64 or aarch64. Keep this value in mind — you will need it when selecting the correct Swift download.

Step 1 — Update Your Rocky Linux 10 System

Always start with a fully updated system. This prevents dependency conflicts and ensures you have the latest security patches applied before adding new software.

sudo dnf update -y && sudo dnf upgrade -y

If a kernel update was included, reboot the system before proceeding:

sudo reboot

Once the system is back online, confirm your OS version:

cat /etc/rocky-release

You should see output similar to Rocky Linux release 10.0 (Obsidian). With that confirmed, you are ready to move forward.

Step 2 — Enable EPEL and CRB Repositories

Rocky Linux 10’s default repositories do not include all the packages needed for Swift. You need to enable two additional repositories: EPEL (Extra Packages for Enterprise Linux) and CRB (CodeReady Builder).

sudo dnf install epel-release -y
sudo dnf config-manager --set-enabled crb
sudo dnf update -y

EPEL is the community-maintained repository that hosts the swift-lang package for RHEL-compatible distributions like Rocky Linux. CRB provides supplementary development libraries — it is the Rocky Linux 10 equivalent of what was called PowerTools in Rocky Linux 8. Without CRB, some of Swift’s build-time dependencies will fail to resolve.

Confirm both repositories are active before moving on:

sudo dnf repolist

Look for epel and crb in the output. If they appear, you are good to go.

Step 3 — Install Required System Dependencies

Swift relies on several system libraries for its runtime and Foundation framework. Install them all at once:

sudo dnf install -y \
  binutils gcc git glibc-static gzip \
  libbsd libcurl libedit libicu \
  libstdc++-static libuuid libxml2 \
  tar tzdata sqlite pkg-config python3

Here is a plain-English breakdown of what each group does:

  • binutils, gcc — linker and compiler tools required to produce Swift binaries
  • libicu, libedit, libxml2 — core Swift runtime and Foundation framework dependencies
  • glibc-static, libstdc++-static — static linking support for producing fully self-contained executables
  • libuuid, libbsd — low-level system utilities used by Swift’s standard library
  • tzdata, sqlite, pkg-config — required by Swift’s Foundation module for date, database, and build configuration handling

Missing any of these can cause cryptic linker errors during compilation. Installing them upfront saves a lot of debugging time later.

Method 1: Install Swift Using Swiftly (Recommended)

Swiftly is Apple’s official Swift toolchain manager for Linux. Think of it like pyenv for Python or nvm for Node.js — it lets you install multiple Swift versions, switch between them instantly, and update to the latest release with a single command. It was formally introduced as a stable 1.0 release in late 2025 and is now the recommended installation path on swift.org.

Download and Initialize Swiftly

Run the following one-liner in your terminal. It downloads Swiftly, extracts it, and initializes it while automatically installing the latest Swift toolchain:

curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \
tar zxf swiftly-$(uname -m).tar.gz && \
./swiftly init --quiet-shell-followup && \
. "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" && \
hash -r

The $(uname -m) portion automatically selects the binary that matches your system architecture. The ./swiftly init command configures Swiftly for your user account and downloads the latest stable Swift toolchain in the same step. The final . env.sh and hash -r lines update your current shell session so you can use Swift commands immediately without logging out.

Verify and Manage Toolchains

Once initialization completes, check the installed Swift version:

swift --version

Expected output looks like:

Swift version 6.x.x (swift-6.x.x-RELEASE)
Target: x86_64-unknown-linux-gnu

To install a specific version instead of the latest, use:

swiftly install --use 5.10

To list all available versions:

swiftly list-available

To update Swiftly itself:

swiftly self-update

Swiftly also supports installing snapshot builds if you want bleeding-edge features:

swiftly install --use main-snapshot

Make the Environment Persistent

The env.sh sourcing applied earlier only lasts for the current session. To make Swift available in every future terminal session, add it to your shell profile:

echo '. "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh"' >> ~/.bashrc
source ~/.bashrc

Method 2: Install Swift via DNF Package Manager (EPEL)

If you prefer a simpler, system-managed installation without worrying about toolchain versions, EPEL’s swift-lang package is a solid option. This method integrates Swift into the standard dnf package lifecycle alongside all your other system software.

Install the Package

sudo dnf install swift-lang -y

Note the package name is swift-lang — not swift. The naming avoids conflicts with other packages. Expect the download to be around 377 MB; installation time depends on your connection speed.

Check the Installed Version

dnf info swift-lang

This displays the version, source repository, and build date. Keep in mind that EPEL packages sometimes lag a release or two behind the upstream Swift version. If you need the absolute latest stable release, Method 1 (Swiftly) is the better choice. For most server-side deployments where version stability matters more than novelty, the EPEL package is perfectly suitable.

Method 3: Manual Tarball Installation

This method gives you complete control over the Swift toolchain location. It is the right choice for air-gapped servers, environments without EPEL, or situations where you need to pin a specific version that neither Swiftly nor EPEL provides.

Download the Toolchain

Visit swift.org/download and copy the URL for the RHEL-compatible release. Then download it directly on your server — Rocky Linux 10 uses RHEL-compatible Swift builds:

wget https://download.swift.org/swift-6.x.x-release/rhel9/swift-6.x.x-RELEASE/swift-6.x.x-RELEASE-rhel9.tar.gz

Replace 6.x.x with the actual version number from the download page.

Extract and Move to /usr/local

tar xzf swift-6.x.x-RELEASE-rhel9.tar.gz
sudo mv swift-6.x.x-RELEASE-rhel9 /usr/local/swift

Add Swift to Your PATH

For the current user only:

echo 'export PATH=/usr/local/swift/usr/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

For system-wide access (all users), add it to /etc/profile.d/:

echo 'export PATH=/usr/local/swift/usr/bin:$PATH' | sudo tee /etc/profile.d/swift.sh
source /etc/profile.d/swift.sh

Adding to /etc/profile.d/ ensures the PATH is set for every user who logs in — useful on multi-user development servers.

Verify the Swift Installation

Regardless of which method you used, run these checks to confirm Swift is properly installed and accessible:

swift --version
which swift

The swift --version command should return the version number and target platform. The which swift command confirms the binary’s location, helping you verify the correct installation path is active.

If you see swift: command not found, the most common cause is a missing PATH update — jump ahead to the troubleshooting section. You can also confirm the full toolchain is functional:

swift -help

This should print the full list of compiler flags, confirming the Swift compiler (swiftc), REPL, and Package Manager are all accessible.

Writing Your First Swift Program on Rocky Linux 10

With Swift installed, let’s confirm everything works end-to-end by writing a small program.

Create the Source File

nano hello.swift

Add this single line:

print("Hello, Rocky Linux 10!")

Save and close the file (Ctrl+O, Enter, Ctrl+X in nano).

Run and Compile

To run the file directly using Swift’s interpreter mode:

swift hello.swift

To compile it into a standalone native binary:

swiftc hello.swift -o hello
./hello

Both should print Hello, Rocky Linux 10!. The key difference: swift interprets the file on the fly, while swiftc compiles it into a native executable with no Swift runtime dependency — making it ideal for production deployments. To explore Swift interactively, launch the REPL by running swift with no arguments. You can type Swift expressions and see results immediately — great for experimenting with language features.

Getting Started with Swift Package Manager

Swift Package Manager (SPM) is built directly into the Swift toolchain — no separate installation needed. It handles dependency management, builds, and testing natively; a mature alternative to npm, pip, or Maven.

Initialize a new executable project:

mkdir MySwiftApp && cd MySwiftApp
swift package init --type executable

Build and run it:

swift build
swift run

SPM creates a structured project layout with a Sources/ directory and a Package.swift manifest. From here, you can add dependencies like Vapor (a full-stack web framework) or Hummingbird (a lightweight HTTP server) by editing Package.swift. Both frameworks are popular choices for building REST APIs and microservices on Rocky Linux servers.

Troubleshooting Common Installation Issues

Even with a clean setup, things can go sideways. Here are the most frequent problems and their solutions:

  • swift: command not found — PATH is not set. Run source ~/.bashrc or re-add the export line to your profile and source it again.
  • libicu or libedit errors on first run — These runtime libraries are missing. Re-run Step 3: sudo dnf install -y libicu libedit libxml2.
  • EPEL package not found — EPEL is not enabled. Confirm with sudo dnf repolist | grep epel, then re-run sudo dnf install epel-release -y.
  • Architecture mismatch during download — Confirm your arch with uname -m and download the matching tarball. Mixing x86_64 and aarch64 binaries will fail immediately.
  • Permission denied when moving to /usr/local — Use sudo when moving the extracted Swift directory. Without elevated permissions, the move to a system directory will fail.
  • Swiftly init hangs or fails — Check your internet connection first. Then verify curl is installed: which curl. If missing, install it with sudo dnf install curl -y.
  • GPG verification errors with Swiftly — Import Swift’s official signing keys first: curl https://www.swift.org/keys/all-keys.asc | gpg --import -

Congratulations! You have successfully installed Swift. Thanks for using this tutorial for installing the Swift Programming Language on Rocky Linux 10 system. For additional help or useful information, we recommend you check the official Swift website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a dedicated and highly skilled Linux Systems Administrator with over a decade of progressive experience in designing, deploying, and maintaining enterprise-grade Linux infrastructure. His professional journey began in the telecommunications industry, where early exposure to Unix-based operating systems ignited a deep and enduring passion for open-source technologies and server administration.​ Throughout his career, r00t has demonstrated exceptional proficiency in managing large-scale Linux environments, overseeing more than 300 servers across development, staging, and production platforms while consistently achieving 99.9% system uptime. He holds advanced competencies in Red Hat Enterprise Linux (RHEL), Debian, and Ubuntu distributions, complemented by hands-on expertise in automation tools such as Ansible, Terraform, Bash scripting, and Python.
Back to top button