How to install Swift on Ubuntu and add syntax highlighting for Sublime Text

I recently started teaching myself Swift, the new Open Source Language from Apple that powers their latest iOS and MacOS apps. In this article, I’ll go over how I installed it on Ubuntu 14.04 and how I got Sublime Text 2 to recognize it’s syntax. Note that there may be better and more comprehensive ways of doing this, I’m just posting what worked for me. If you have any suggestions to improve this, please be sure leave a comment.

Directions adapted from this post.

Start by clicking here and downloading the latest snapshot for Linux. For me it was called Ubuntu 14.04 Swift Development Snapshot, posted on Feb 3, 2016.

Then you’ll want to unzip the tarball.

tar -xzf swift-DEVELOPMENT-SNAPSHOT-2016-02-03-a-ubuntu14.04.tar.gz

Inside you’ll find a usr directory; move that somewhere you’ll remember for later. I put it in my home directory. Update your PATH variable to include the usr/bin directory inside. Note the following is only a temporary PATH update for the current session on the terminal.

mkdir /home/jamil/swift
mv swift-DEVELOPMENT-SNAPSHOT-2016-02-03-a-ubuntu14.04/usr /home/jamil/swift

export PATH=/home/jamil/swift/usr/bin/:"${PATH}"

You should be able to run the following now.

swift --version
Swift version 3.0-dev (LLVM 524cfeb800, Clang f66c5bb67b, Swift c33f2faad2)
Target: x86_64-unknown-linux-gnu

Before you can compile any files, you’ll need to install clang.

sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

Almost there. Now let’s take it for a spin. Create a helloworld.swift file somewhere using your favorite text editor. Enter the following line. Swift looks pretty simple doesn’t it?

print("Hello, World!")

Now let’s compile.

swiftc helloworld.swift

And finally run it!


With me so far? You can stop here if that’s all you plan to do. If you use Sublime Text 2, follow these steps to include Swift syntax highlighting. These steps will require restarting ST2 a few times after you run commands.

Follow the instructions here to install Package Control for Sublime Text if you don’t have it already. It’s just a copy’n’paste command line to the Sublime Text console.

Restart Sublime Text.

Then install the Swift-Sublime-Package with the simple instructions found here. All you have to do is search for the Swift package and hit Enter.

Restart Sublime Text.

When you create a new file in Sublime Text, go to View > Syntax and you should see Swift as one of the choices. Pretty cool, huh?

What are your thoughts?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s