How to set up the Apple Swift language on Linux
Apple’s Swift programming language works on Ubuntu Linux, and the language is open source. If you’re a developer looking to set up the Apple Swift language on Linux, follow along with this guide, and you’ll be ready to start writing programs in no time!
Ubuntu Linux setup
Apple’s Swift programming language is available on Linux officially, but only for Ubuntu Linux, and distributions based on Ubuntu. As of now, Apple hasn’t ported the language to any other mainstream Linux OS.
Swift’s official software release on Ubuntu covers versions 18.04, 16.04, and 14.04. However, if you are using Debian Linux, you may be able to get Swift working with the Ubuntu version. Keep in mind that your OS will not have official support from Apple, as Debian isn’t the targeted distribution.
Getting Swift working on Ubuntu is more tedious than you might think. As it turns out, Apple hasn’t taken the time to put out any easy to install DEB packages. Instead, those looking to write Swift applications on Ubuntu will need to get it working by hand.
The first step in installing Apple’s Swift on Ubuntu Linux is to download the latest release. To do this, open up a terminal window by pressing Ctrl + Alt + T or Ctrl + Shift + T and use the wget download command below.
18.04
wget https://swift.org/builds/development/ubuntu1804/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu18.04.tar.gz
16.04
wget https://swift.org/builds/development/ubuntu1604/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu16.04.tar.gz
14.04
wget https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu14.04.tar.gz
After downloading the latest release of Swift to your Ubuntu Linux PC, you must install the various dependencies it requires to make everything run correctly. These dependencies are Clang and a few other packages.
sudo apt install clang libcurl3 libpython2.7 libpython2.7-dev
Once the dependencies for Swift are set up on your Ubuntu Linux PC, it is time to extract the latest Swift TarGZ archive you downloaded earlier.
tar xvf swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu*.tar.gz
When everything is done extracting, you must move the Swift files into the “/usr/share/swift/” directory. To do this, use the commands below.
sudo mv swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu* /usr/share/
sudo mv /usr/share/swift-DEVELOPMENT-SNAPSHOT-2019-09-30-a-ubuntu*/ /usr/share/swift/
With all of the Swift files in place, you must set up Swift in your path. To do this, enter the following commands in a terminal window.
echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc source ~/.bashrc
You can then start using Swift with:
swift --help
Arch Linux AUR setup
Apple does not officially support the Arch Linux operating system, and Swift will not make an official appearance on the development website any time soon. Thankfully though, this doesn’t matter, as the Arch community has found a way to make Swift work regardless through the AUR.
If you’d like to work with the Swift programming language on Arch Linux, a lot of software dependencies must be installed. To install all of these dependencies efficiently, and quickly, we will walk you through how to set up the Trizen AUR helper.
The first step in installing the Trizen AUR helper, you must install the Base-devel and Git packages using the Pacman package manager in a terminal window. Using the commands below, install the packages.
sudo pacman -S git base-devel
After installing the Base-devel and Git packages on your Arch Linux PC, use the Git tool to download the Trizen AUR helper snapshot.
git clone https://aur.archlinux.org/trizen.git
Once the Trizen package is done downloading to your Arch Linux PC, move the command-line window into the “trizen” directory.
cd trizen
Build the Trizen AUR helper on your Linux PC by running the makepkg command.
sudo makepkg -sri
Now that the Trizen AUR helper is installed on your Arch Linux PC installing Apple’s Swift programming language is very easy. To do it, enter the command below and follow the prompts on-screen.
trizen -S swift
Fedora Linux setup
Apple’s Swift does not officially support Fedora Linux. However, as the Fedora operating system has a lot of development-minded users, Swift has been ported over and is installable from the official Fedora software repositories.
If you’re looking to get Swift working on your Fedora Linux workstation, open up a terminal window by pressing Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. Then, use the Dnf package manager to install “swift-lang.”
Note: if you are an OpenSUSE Linux user, consider downloading the “swift-lang” package here to get it working on your system. Use at your own risk!
sudo dnf install swift-lang
Snap package setup
The invention of Snap packages has made installing complex technologies like the Apple Swift language on Linux incredibly easy. So, if you’re using a Linux operating system that is compatible with Snap packages, use the command below to install Apple’s Swift programming language.
Note: Snap packages requires the Snapd runtime be enabled. To enable this runtime, follow our setup guide on how to get Snap packages working.
sudo snap install swift
Are you having trouble using the swift Snap package? An alternative Apple Swift Snap is on the store. To install it, use the command below.
sudo snap install swift-language