How to Install Swift on Fedora 39, 38 Linux

Apple has developed Swift, a robust and high-performance programming language that excels in building applications for iOS, macOS, watchOS, and tvOS. As an open-source language, Swift also runs on Linux and various non-Windows platforms, offering significant advantages for developers working within the Fedora Linux ecosystem. Here, we’ll explore the key features of Swift, preparing us to install Swift on Fedora Linux.

Key Features of Swift:

  • Fast and Efficient: Swift ensures quick execution, enhancing performance.
  • Secure Coding: It emphasizes safety with features that help avoid common programming errors.
  • Interactive Development: Swift Playgrounds and REPL allow immediate code testing and interaction.
  • Modern Syntax: The language adopts a clean and expressive syntax that simplifies coding tasks.
  • C and Objective-C Interoperability: Swift works seamlessly alongside existing C and Objective-C code, enabling developers to use various libraries and frameworks.
  • Supportive Community: An expansive community contributes to a growing repository of tools and resources.
  • Open-Source Contribution: Swift’s open-source nature invites continuous updates and improvements.
  • Cross-Platform Compatibility: Swift extends its reach beyond Apple’s ecosystem, supporting Linux and other platforms.

Swift marries speed with safety, offers interactive coding sessions, and has a modern syntax that simplifies learning and development. By integrating Swift into a Fedora Linux system, developers gain a flexible toolset for creating high-quality, secure, and interactive applications. With these capabilities in mind, this guide will take you through the straightforward steps to install Swift on Fedora Linux and access the Swift REPL for an enhanced programming experience.

Install Swift on Fedora Linux via DNF

Step 1: Update Fedora Before Swift Installation

Prioritize your Fedora system’s integrity by updating all packages. Run the following command to refresh your system’s package database and upgrade the packages to their latest available versions:

sudo dnf upgrade --refresh

Step 2: Install Swift Programming Language via DNF Command

Leverage Fedora’s cutting-edge software offerings by installing the Swift programming language. Fedora’s repositories are frequently updated, often providing the latest version of Swift. To install Swift, use the DNF command as shown:

sudo dnf install swift-lang

After installation, confirm that Swift is correctly installed and check the installed version by executing the following:

swift --version

This command will display the current version of Swift installed on your system, ensuring you’re working with the version you expect.

Connect to the Swift REPL on Fedora Linux

Accessing Swift REPL

Initiate your Swift coding session on Fedora by launching the Swift REPL, an interactive shell that evaluates Swift code in real-time. Enter this command in the terminal:

swift repl

Utilizing Swift REPL for Development

Within the Swift REPL, your Swift code snippets come to life immediately. Here, you can execute Swift statements on the fly and incorporate C libraries with ease. Start by testing simple expressions:

let name = "Joshua James"

Expand your Swift code’s functionality by integrating the GNU C Library:

import Glibc // imports GNU C Library

Create and use variables, leveraging the C standard library functions, like generating a random number:

var ln = random () % 100

Then, you can print custom messages to the console:

print("Thank You LinuxCapable.com for learning how to Install Swift on Fedora")

When you finish your coding session, gracefully exit the REPL environment by typing:

:q

This command will close the REPL, allowing you to return to your Fedora system’s standard terminal interface.

Additional Commands For Swift on Fedora Linux

Update Swift on Fedora

To ensure your Swift installation remains current, periodically update your Fedora system, which includes Swift, among other packages. Execute the command below to refresh and update your packages:

sudo dnf upgrade --refresh

Executing this command not only updates Swift but also keeps the entire system up-to-date, reinforcing security and stability.

Remove Swift From Fedora

In the event that Swift is no longer required, its removal is straightforward using Fedora’s DNF package manager. Remove Swift and its components by issuing this command:

sudo dnf remove swift-lang

This action will cleanly uninstall the Swift programming language from your Fedora system.

Conclusion

In this guide, you were provided with steps to install the Swift programming language via Fedora’s default repository and access the interactive environment of the Swift REPL, allowing you to write and test code. Additionally, tips were given on how to update and remove Swift in the future if necessary.

Leave a Comment


Your Mastodon Instance
Share to...