What is Swift?
If you haven’t heard of it before, Swift is Apple’s newest programming language intended to replace Objective-C and become the primary language for building Mac OS X and iOS applications. It’s very easy to learn the language as it’s clean and has a similar syntax to other popular programming languages.
In any case, if you’re interested in using or learning Swift, it’s now available for Linux! Right now Apple only has released snapshots made for Ubuntu 14.04 and 15.10, but opportunities to install Swift support on other distributions will certainly come in the near future. For now, here’s how to get it going on Ubuntu.
How to Install It
First, you’ll need to visit the Swift download page and grab the latest version (at time of writing, there are only development snapshots available — stable releases will come soon, so it’s your choice which of the two you’d like to use). Once it’s downloaded, open the .tar file by double-clicking on it and then extract the folder that lies within to any location of your preference. This will become the location of your Swift installation.
Next, you’ll need to install some dependencies that Swift needs to run. You can easily install them by opening a Terminal and running
sudo apt-get install clang libicu-dev
Finally, before you close the terminal window, type
is the path to the bin folder inside the usr folder inside the Swift folder that you extracted out of the .tar file. So if you just extracted theSwift folder to your Downloads folder, the path would be something like
The export command will allow you to simply call
in a Terminal and it will know where to look. Putting this line into the .profile text file will make this command permanent — otherwise its effect would be lost when you log out, shutdown, or restart your computer.
To make sure that Swift works, you can type
into a Terminal and it should display some version information. Congrats! You now have Swift working on your Ubuntu system!
How to Run Swift Code
To run a Swift file, all you need to do is run
It will compile and run automatically. You can also simply just run
which will bring up an interactive shell with which you can run Swift code line by line.
Finally, you can also make executables from your Swift code. All you need to do is the following:
- Create a project folder with any name you like, then inside there create a folder with the name “sources”.
- Place all of your code files inside the source folder.
- Create a text file named “Package.swift” in the project folder (but outside the sources folder) and put at least the following in it:
import PackageDescription let package = Package( name: "package_name_here_and_keep_quote_marks" )
while the project folder is the working directory. You will find the executable under
Swift At Your Fingertips
What do you think about Swift? Does it have a future as a common, universal language like C/C++ and Java? Let us know in the comments!