How to install Swift on Ubuntu

Apple Inc. just announced its new programming language, Swift, to be open source. As a new programming language, it quickly becomes very popular as one of the fastest growing programming language in history. By making it open source, community around the world can help to make it available everywhere.

At the time of this writing, it is still in development snapshot stage meaning it is not official release yet and available for both Apple platform and Linux (Ubuntu 14.04 and Ubuntu 15.10).

How to install Swift on Ubuntu

This article will show you how to install Swift on Ubuntu. If you use Ubuntu Linux version 14.0 or 15.10 you can follow the installation guide available on the official Swift website. I try to make it simpler and quicker way to install and run Swift on Ubuntu. After you install the required dependency packages, importing PGP key, and download the package you need to extract the package and add swift into system PATH.

$ tar zxf swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10.tar.gz 
$ mv swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10 swift
$ export PATH=$PATH:/home/fuad/swift/usr/bin

As you can see in the command above, I renamed swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10 directory/folder to swift to make it short. In the export command, rename the /home/fuad/ with yours.

Now swift should be in your system PATH and is ready.

$ swift
Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
  1> let message = "Hello Swift!!"
message: String = "Hello Swift!!"
  2> print(message)
Hello Swift!!
  3> :q

Type :q to quit from Swift. Below is the screenshot.

Swift Programming Language on Ubuntu


The PATH will reset to default after system reboot  or closing the Terminal application. To make it permanent, you need to add it into .profile file in your $HOME directory like in the image below

Set Swift on system path