# Hello World on Koding: Swift 3 --- author: Bee Jay twitter: @pak_lebah created: 2015-12-12 updated: 2016-09-14 for **Swift 3** categories: ![](https://img.shields.io/badge/program-hello%20world-lightgrey.svg) ![](https://img.shields.io/badge/lang-swift-orange.svg) ![](https://img.shields.io/badge/swift-v3.0-orange.svg) ![](https://img.shields.io/badge/os-ubuntu-red.svg) ![](https://img.shields.io/badge/host-koding.io-green.svg) --- ## Introduction In June 2014, at WWDC 2014 event, [Apple](http://apple.com) surprised programmers all around the world by introducing a new programming language dubbed "**Swift**". Apple promises many things with this new programming language, some of them are ease of use, great performance, and code safety. It also introduces a new programming paradigm called protocol oriented programming. And it will become the official programming language on Apple platforms, slowly replacing Objective-C. As if it's not enough, along with the release of Swift v.2.0 at WWDC 2015 event, Apple also announced that Swift will become an open source project and support Linux as well. And by the end of 2015, along with Swift v.2.2, Apple officially release Swift as an open source project with its own official website at [swift.org](http://swift.org). This move is mostly accepted positively by many programmers. Many software experts say that this move will boost Swift into popular programming language in relatively short time. And at September 14, 2016, Swift got its third version released. This Swift v.3.0 is a backward-incompatible and source-breaking version which means its new syntax breaks the old one from previous releases. Many things have changes in Swift v.3.0 as detailed [here](https://swift.org/blog/swift-3-0-released/). The previous versions is deprecated, obviously. So, if you want to learn Swift, you should jump directly to Swift v.3.0. ## Installation Swift fortunately supports Linux Ubuntu since the first time it went open source. As Koding is also using Ubuntu, the installation should be easy enough. This tutorial should work on any Ubuntu versions, just make sure you download the correct Swift package for you Ubuntu. Alright, let's try it out... 1. First we should download the correct Swift file for our VM. As Koding is using Ubuntu 14.04, we will download the appropriate version. We're going to use `wget` to dowload the file. Open a terminal, assuming you're on your home directory, type this: ```bash $ wget https://swift.org/builds/swift-3.0-release/ubuntu1404/swift-3.0-RELEASE/swift-3.0-RELEASE-ubuntu14.04.tar.gz ``` 2. Download the package signature file. Type this: ```bash $ wget https://swift.org/builds/swift-3.0-release/ubuntu1404/swift-3.0-RELEASE/swift-3.0-RELEASE-ubuntu14.04.tar.gz.sig ``` 3. Download and import the package associated PGP keys. Type this: ```bash $ wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - ``` 4. Download and import the automatic signing keys for Swift. Type this: ```bash $ wget -q -O - https://swift.org/keys/automatic-signing-key-1.asc | gpg --import - ``` 5. Download and import the signing keys for the package. Type this: ```bash $ wget -q -O - https://swift.org/keys/release-key-swift-3.x.asc | gpg --import - ``` 6. To make sure that we got the correct Swift files, do the file verification. Type this: ```bash $ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift ``` then follow by this: ```bash $ gpg --verify swift-3.0-RELEASE-ubuntu14.04.tar.gz ``` You might see some warnings, but as long as you see the text below... ``` gpg: Good signature from "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>" ``` you could simply ignore any other messages. 7. Install the required clang development tools. Type this: ```bash $ sudo apt-get update ``` then follow by this: ```bash $ sudo apt-get install clang libicu-dev ``` Just press *y* (yes) everytime it asks for confirmation. 8. As all the requirements are set, now extract the archive. Type this: ```bash $ tar xzf swift-3.0-RELEASE-ubuntu14.04.tar.gz ``` 9. For convenience, it's better to rename the Swift folder. Type this: ```bash $ mv swift-3.0-RELEASE-ubuntu14.04.tar.gz/ swift-3.0/ ``` 10. The last step, type this: ```bash $ export PATH=~/swift-3.0/usr/bin:"${PATH}" ``` > ✔︎ **TIP** > For convenience, open your `.bashrc` file and at the last line add this: > ``` > PATH=~/swift-3.0/usr/bin:"${PATH}" > ``` 10. If everything goes well, you should be able to use Swift by now. To test it, type this on the terminal: ```bash $ swift -version ``` It should return your currently installed Swift version. It should look like this: <pre> Swift version 3.0 (swift-3.0-RELEASE) Target: x86_64-unknown-linux-gnu </pre> If you see similar text like the above then congratulation, you've just installed Swift successfully! > ✔︎ **TIP** > As Swift has been installed on your VM, you may safely delete the downloaded `.tar.gz` and `.tar.gz.sig` files to save some spaces. ## First Program Since you already have got Swift installed on your system, let's play around with it. Let's write a simple Hello World program. 1. For convenience, let's install Koding command to open editor from the command line. Open your terminal and type this: ```bash $ kpm install kdbin ``` Wait for a second until it finishes its job. You may skip this first step if you already have `kdopen` installed on your VM. 2. Create a new swift source file name `hello.swift`. Type this: ```bash $ kdopen hello.swift ``` 3. After the editor open the file, type this code: ```swift print("Hello World from Swift!") ``` Then save the file. 4. Back to your terminal. Run the program, type this: ```bash $ swift hello.swift ``` If nothing goes wrong, it should display `Hello World from Swift!` on the console. 5. The above step is using swift as an interpreter (REPL). If you want to try the swift compiler, type this: ```bash $ swiftc hello.swift ``` Notice the additional `c`, it means "compiler". If no error message is shown, it means the compilation is successful. Swift produces an executable binary file. To run it, simply type this: ```bash $ ./hello ``` It should also display `Hello World from Swift!` on the console. Here's an old Hello World demo (still using Swift v.2.2) video: ![](img/swift-2.2-ubuntu.gif) Of course a simple Hello World program wouldn't be enough. To learn more about Swift language, you could read the online Language Guide [here](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html). You could also download the ebook from [here](https://swift.org/documentation/TheSwiftProgrammingLanguage(Swift3).epub) (.epub). > ✔︎ **TIP** > If you just want to learn the Swift language without bothering to install Swift on your VM, you may try my online Swift runner [here](webswift.cgi). Have fun! ## What's Next Swift is a brand new programming language. It's still being actively developed and improved by Apple with the help of programmers all around the world. Apple puts its bet on this language for its future. Apple also aggresively pushes [Swift](http://apple.com/swift) to education field in order to reach the young generations. If you really want to master this language, you should actively monitor Swift official website and follow the [mailing lists](https://swift.org/community/#mailing-lists). Many things are being discussed to make Swift the ultimate programming language of the future. It's also fun to watch a language growing. Alright... that's all folks! :) ---
⬅︎ Back Top ⬆︎