I give a big thanks to the man sitting behind swift-arm.com. He made a tremendous effort to make the Swift setup easier than ever.
Hello guys, In this post, I will talk through on installing Swift environment for programming on Raspberry Pi. The Swift version will be set up is Swift 4.1.1
This tutorial is done on Raspberry Pi Model 3 B+ with Raspbian Stretch Lite. If you haven’t set up the Raspbian OS, learn more here
Ok, No more word, let’s started.
Set it up
First and foremost, plug the cord and remotely connect to the Raspberry from your computer over ssh in the terminal. Just simply use the following command
ssh pi@raspberry_ip_here
(The default user is pi, password is raspberry)
Second, We need to update apt-get, use this command
sudo apt-get update
sudo apt-get upgrade
Third, We need some software in place
sudo apt-get install git
sudo apt-get install nano
Ok, Now We’re good to set up Swift. This will be done by the help from author of swift-arm.com
curl -s https://packagecloud.io/install/repositories/swift-arm/debian/script.deb.sh | sudo bash
sudo apt-get install swift-4.1-RPi23-RaspbianStretch
Ok, you’re done. Now, let’s double check again. Use this following command to check the Swift version set up on Raspberry Pi.
swift -version
When you get the above message, then congratulation!. Swift is ready.
Make Hello world!
Ok, let’s make a simple program to say hello.
Create a swift file to print out “hello world”
echo 'print("hello world!")' > hello.swift
Finally, run it
swift hello.swift
To continue editing the program and do something exciting, you can open the file hello.swift by nano, vim or whatever. My favorite is nano.
nano hello.swift
What’s next
Do you feel excited? Let’s write any simple program in swift and share your experience. If you have any trouble, please feel free to ask here.
Next, I’ll share you guys the most convienience and profressional way to work on a Swift project.
You’ll be able to code Swift with XCode on MAC OS or Visual Studio Code, so stay tune.
Reference resources:
- Swift for Raspberry Pi – http://swift-arm.com/2018/08/02/swift-4-1-2-updated-for-raspberrypi-2-3/
Hello Hai! First of all, thanks for all your work to make Swift easier to use on Raspberry. I am having some problems installing Swift following the steps of the Swift-Arm website, my Raspbian OS can’t find the swift-4.1-RPi23-RaspbianStretch (or others) using apt-get, but I can find the Swift 5. The curl command returns the following errors: bash: linha 1: erro de sintaxe próximo ao token inesperado `newline’
bash: linha 1: `’
So, using another page, curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash (https://swift-arm.com/2019/01/07/official-swift-arm-community-releases/), it works. And now Swift 5 appears, but today I’m studying if I can use it. If you have any ideas, I will appreciate your words.
I`m new on Swift and Raspberry, sorry if I’m writing dumb things. And sorry for my English, I’m from Brazil, a lot of time without using it, a lot of rust. 🙂
Thanks again! Best regards.
LikeLike
You can use any version of Swift, it doesn’t matter if you begin a new Swift project from scratch. If you can’t find the Swift-4.1-xxx, I guess the author did took it down. You can try Swift 5. Check this out https://swift-arm.com/install-swift
LikeLike