Tugulab Blog.

Installing Swift 3.0 preview on a Raspberry Pi 2/3 with Raspbian

We’re halfway trough our journey of controlling electric circuits and hardware with Swift and a Raspberry Pi. If you missed anything, here…
author avatar

clacla

We’re halfway trough our journey of controlling electric circuits and hardware with Swift and a Raspberry Pi. If you missed anything, here lie the answers to your questions.

Ssh into your RPi:

ssh pi@raspberrypi.local
(password raspberry)

Open the apt sources file:

sudo nano /etc/apt/sources.list

Uncomment the last line:

deb-src [http://archive.raspbian.org/raspbian/](http://archive.raspbian.org/raspbian/) jessie main contrib non-free rpi

Update your system and install some required packages:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install clang git

Installing Swift 3.0 build at root level. We’re going to use Joe Bell’s incremental builds:

cd ~
wget [http://47.186.11.166/job/Swift-3.0-ARMv7-ubuntu1410/29/artifact/swift-3.0-2016-11-03-armv7-ubuntu14.04.tar.gz](http://47.186.11.166/job/Swift-3.0-ARMv7-ubuntu1410/29/artifact/swift-3.0-2016-11-03-armv7-ubuntu14.04.tar.gz)
sudo tar -xzpf swift-3.0-2016-11-03-armv7-ubuntu14.04.tar.gz -C /
rm swift-3.0-2016-11-03-armv7-ubuntu14.04.tar.gz

You have installed Swift!! Now start screaming like Steve Ballmer in a moment of uncontrolled excitement.

Let’s write our first Swift script to see that it’s actually working:

mkdir swifttest
cd swifttest
nano main.swift

Add this simple hello world (which ironically doesn’t say “hello world”):

import Glibc
import Foundation

let currentDate = NSDate()
print("My first Swift binary! Executed at \(currentDate)”)

Compile and run:

swiftc main.swift
./main

Well done! You’re ready for the world. Now go and write beautiful swift code. Or turn some LED on with Swift!