Installing Swift on Ubuntu 18.04 LTS 💻

January 31, 2020
Swift Linux

In this guide, I’m going to write the commands and steps needed to install Swift on Ubuntu 18.04 LTS. My server is going to be hosted by Linode, but it should work on any computer running Ubuntu 18.04 LTS. Since I’m doing this on Linode, all of the instructions will be how to install Swift using the command line.

Let’s get started by accessing your Ubuntu 18.04 LTS instance. For me, this means using SSH to access my server.

Note : When installing, I’m going to put sudo before my commands because we need root access to install into some of the directories. If you have root access, you should not need sudo.

1. Install clang and libicu-dev

Two packages need to be installed since they are dependencies. I want to explain what they are before actually installing them.

clang

clang provides tooling infrastructure for programming languages in the C programming languages. It acts as a compiler.

libicu-dev

libicu-dev provides full-featured Unicode and locale support. This allows for Unicode to be used in our code.

How to install

sudo apt-get install clang libicu-dev

apt-get is a command line tool that handles packages. And other tools from the APT library.

2. Download the Swift files

Apple hosts the Swift files to download on Swift.org/downloads. You can go there to get the URL to download the latest release of Swift or the version that you need.

Note: As of writing this guide, the latest release is 5.1.3 which is what I will use in the commands

Navigate to the location where you want to download the binary of the Swift version you want to install. I keep mine in the src folder, so the command below will take me there.

cd src

Now, let’s download the binary files.

wget [swift.org/builds/sw...](https://swift.org/builds/swift-5.1.3-release/ubuntu1804/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu18.04.tar.gz)

Let this command finish, and then continue to step 3.

3. Extract the files

tar -xvzf swift-5.1.3-RELEASE*

The *, after swift-5.1.3-RELEASE, acts as a wild card so that tar -xvzf can find the file that starts with swift-5.1.3-RELEASE.

This is going to extract the files and create a folder of the swift binary files named swift-X.X.X-RELEASE-ubuntu18.04. X.X.X will be the version number that you installed.

4. Add this to the PATH

We need to add the absolute path, the location where the binaries were extracted, of the binaries to the PATH variable that way we can actually use the swift command in the command line.

Navigate to the location used in steps 2 and 3 and use the command pwd to see the full path to the binaries. Now to add that path to the PATH.

export PATH=path_shown_using_pwd

My command looks like this:

export PATH=/home/mw/src/swift-5.1.3-RELEASE-ubuntu18.04

5. Verify the Install

Swift is now installed. Let’s verify that it works use the following.

swift -version

The terminal should show what version you are using. Mine shows Swift version 5.1.3 and some more things about the version, and that is it!


If you enjoy my posts, streams, and apps, consider buying me the juice of life that is coffee.

or support my work monthly on Patreon.

Supporting me on Ko-Fi, Buy Me a Coffee, or on Patreon will have your name listed as a supporter at the end of my streams for that month and on my supporters page.