This article explains how to install Swift on Ubuntu 24.04.
Swift is a powerful and intuitive programming language developed by Apple, primarily for iOS, macOS, watchOS, and tvOS development. However, it has also gained popularity for server-side and cross-platform programming.
Swift can be used to develop applications not just on Apple platforms but also on Linux. This allows developers to create applications that run on multiple operating systems.
Installing Swift on Ubuntu allows developers who prefer or are already working in a Linux environment to take advantage of these benefits.
Prepare Ubuntu
Before installing Swift, you must know the release and codename of the Ubuntu version you are running.
Then, download the appropriate version of Swift for your system.
Run the command to verify the Ubuntu release and codename of your system.
lsb_release -a
If you run Ubuntu 24.04, the command should return release version 24.04 and codename noble.
After that, install these packages on Ubuntu.
sudo apt-get install binutils git gnupg2 libc6-dev libcurl4-openssl-dev libedit2 libgcc-13-dev libncurses-dev libpython3-dev libsqlite3-0 libstdc++-13-dev libxml2-dev libz3-dev pkg-config tzdata unzip zlib1g-dev
Download Swift
Once your Ubuntu system is ready, use the download page to download your system’s latest version of Swift.
You can also use the command below to download Swift 6.0.3 binary. Replace the version number with the latest.
wget https://download.swift.org/swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04.tar.gz
After downloading the file and before installing, download the Swift GPG key for its packages by running the command below.
wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
gpg --keyserver hkp://keyserver.ubuntu.com --refresh-keys Swift
Next, download the Swift signature file for the installer and verify it by running the command below.
wget https://download.swift.org/swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04.tar.gz.sig
gpg --verify swift-6.0.3-RELEASE-ubuntu24.04.tar.gz.sig
Finally, extract the downloaded installer and move the file into the /opt directory.
tar xzf swift-6.0.3-RELEASE-ubuntu24.04.tar.gz
sudo mv swift-6.0.3-RELEASE-ubuntu24.04/* /opt/swift
Configure Swift
After extracting the file, add the Swift command to your command PATH by running the command below.
echo "export PATH=\$PATH:/opt/swift/usr/bin" >> $HOME/.profile
source $HOME/.profile
To verify that Swift is installed and ready, run the command below.
swift --version
The command should return the current version that was installed.
You can start Swift by running the command below.
swift
That should do it.
Conclusion:
In conclusion, installing Swift on Ubuntu 24.04 provides developers with a powerful tool for cross-platform development. Here are the key takeaways:
- Versatility: Swift allows for developing applications across multiple operating systems, enhancing your ability to reach a broader audience.
- GPG Key Security: Downloading and verifying the Swift GPG key ensures the integrity and authenticity of your installation.
- Easy Installation: The installation process is straightforward, making it accessible for developers of all experience levels.
- Path Configuration: Properly setting the command PATH is essential for utilizing Swift commands seamlessly in your terminal.
- Ready for Development: Swift is instantly available to develop robust applications in a Linux environment after installation.
By following these steps, you can successfully leverage the capabilities of Swift on Ubuntu, expanding your development toolkit.
Leave a Reply