Set up Swift environment on Raspberry Pi (part 2/2)
I’d like to give a big thanks to the man sitting behind swift-arm.com. He made a tremendous effort to make the Swift env set up easier than ever.
I will walk through 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 -> Set up Swift environment on Raspberry Pi (part 1/2)
After this, We should be good to start off
How to set up
Firstly, boot up the little pi, and remotely connect to the pi machine 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 updatesudo apt-get upgrade
Third, We need some software in place
sudo apt-get install gitsudo 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 bashsudo 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 walk you guys some more convenience and professional way to work on a Swift project.
You’ll be able to code Swift with XCode on MAC OS or Visual Studio Code, learn more here
Compile Swift for Raspberry Pi by XCode
or
Compile Swift for Raspberry Pi by Visual Studio Code
Originally published at http://swiftreviewercom.wordpress.com on December 21, 2018.