Apple has released its brand new programming language for Linux, too.

If you want to try it you should have a PC running Linux Ubuntu, if you have a windows based PC and you don’t want install Linux on it you can run the following few steps to run it on a virtual machine.

What you need.

  1. VirtualBox, to build your virtual machine
  2. Ubuntu Linux, the Operating System for the virtual machine
  3. The last version of the swift programming language released by Apple.

Step 1 – VirtualBox download
Download virtualbox for your OS from here

Step 2 – Install VirtualBox
Follow the instructions of the VirtualBox installer

Step 3 – Download Ubuntu
Download Ubuntu Linux from Ubuntu.com, note that you can use any version of ubuntu since 14.04, anyway for this tutorial I’m going to use Ubuntu Server 15.10.

Step 4 – Install Ubuntu on VirtualBox
Start your VirtualBox and create a new Ubuntu system using the .iso image downloaded at step 3.

swift_ubuntu_virtualbox

Step 5 – Download swift
From your PC open a browser window and goto the following address: https://swift.org/download/#latest-development-snapshots.

Copy the link address at “Ubuntu 15.10 Swift Development Snapshot”
Start your new ubuntu linux virtual machine and login into the shell.
Issue the following command:

wget https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu15.10.tar.gz

where https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu15.10.tar.gz is the link copied in the previous step.

Step 5 – Install swift
From the command line issue the following two commands to update your ubuntu system and install the linux standard development environment:

gg1@ubuntu15.10 $ sudo apt-get update
gg1@ubuntu15.10 $ sudo apt-get install clang libicu-dev

install the swift language:

gg1@ubuntu15.10 $ tar zxvf swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu15.10.tar.gz

move the expanded tarball in a convenient directory:

gg1@ubuntu15.10 $ sudo mv swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu15.10 /usr/bin/swift/

prepare the environment of your user:

gg1@ubuntu15.10 $ echo "export PATH=/usr/bin/swift/usr/bin:\"\${PATH}\"" >> .profile

Step 6 – Test swift with simple hello world
with your favourite editor create the helloworld.swift file containing the following swift code

import Foundation
import Glibc
    print("Hello World!")

Compile the helloworld program using:

gg1@ubuntu15.10 $ swiftc helloworld.swift

run your program

gg1@ubuntu15.10 $ ./helloworld
Hello world!

Great,
Your new swift language is ready to run on ubuntu server!