{"id":4386,"date":"2021-08-26T06:04:30","date_gmt":"2021-08-26T11:04:30","guid":{"rendered":"https:\/\/dev.iachieved.it\/iachievedit\/?p=4386"},"modified":"2021-08-26T06:04:30","modified_gmt":"2021-08-26T11:04:30","slug":"swift-on-linux-in-2021","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/swift-on-linux-in-2021\/","title":{"rendered":"Swift on Linux In 2021"},"content":{"rendered":"<p>It has been nearly 6 years since Apple first <a href=\"https:\/\/swift.org\/blog\/welcome\/\">open sourced the Swift language<\/a> and brought it to Linux.  In that time we&#8217;ve seen the rise (and sometimes fall) of server-side frameworks such as <a href=\"http:\/\/zewo.io\/\">Zewo<\/a>, <a href=\"https:\/\/github.com\/Kitura\/Kitura\">Kitura<\/a>, and <a href=\"https:\/\/vapor.codes\/\">Vapor<\/a> as well as porting Swift to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Single-board_computer\">SBC devices<\/a> such as the Raspberry Pi and Beaglebone.<\/p>\n<p>I recently checked in with some folks in the Swift ARM community to find out if there was an easy way to install the latest version of Swift on Ubuntu.  <a href=\"https:\/\/swift-arm.com\/author\/futurejones\/\">FutureJones<\/a> pointed me to a Debian-based repository he&#8217;s been working on at <a href=\"https:\/\/swiftlang.xyz\/public\/\">Swiftlang.xyz<\/a>.  A nicely put together repo, Swiftlang.xyz supports multiple flavors of Debian and Ubuntu OSes <i>as well as<\/i> both x86 and ARM architectures!  I&#8217;ve installed Swift 5.4 and the upcoming 5.6 release with great success.<\/p>\n<p>Using https:\/\/swiftlang.xyz\/public\/ is a piece of cake with an installer script to configure your <code>apt<\/code> repository list automatically.  <code>arkansas<\/code> below is an Ubuntu VM running on Apple Silicon with Parallels.<\/p>\n<p>Type <code>curl -s https:\/\/swiftlang.xyz\/install.sh | sudo bash<\/code> to get started.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/releaseType.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/releaseType.png\" alt=\"\" width=\"559\" height=\"321\" class=\"aligncenter size-full wp-image-4388\" \/><\/a><\/p>\n<p>I want to use Swift 5.6 so I&#8217;ll select option 2 which will include the <code>dev<\/code> repository in my <code>apt<\/code> sources.<\/p>\n<pre class=\"lang:sh decode:true \" >root@arkansas:~# cat \/etc\/apt\/sources.list.d\/swiftlang-release.list\ndeb https:\/\/archive.swiftlang.xyz\/ubuntu\/ hirsute main dev\ndeb https:\/\/swiftlang.xyz\/ubuntu\/ hirsute main dev<\/pre>\n<p>Now it&#8217;s time to install Swift through the provided <code>swiftlang<\/code> package.  <code>apt-get install swiftlang<\/code> is all it takes.<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/swiftPackages.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/swiftPackages.png\" alt=\"\" width=\"558\" height=\"365\" class=\"aligncenter size-full wp-image-4391\" \/><\/a><\/p>\n<p>Once installed let&#8217;s kick the tires a bit.  First, typing <code>swift<\/code> in the terminal will bring up the REPL:<\/p>\n<pre class=\"toolbar-overlay:false lang:sh decode:true \" >root@arkansas:~# swift\nWelcome to Swift version 5.6-dev (LLVM ba0b85f590c1ba2, Swift d18133629449a50).\nType :help for assistance.\n  1&gt;<\/pre>\n<p>To really test things out let&#8217;s hit a REST API and destructure the response.  For this we&#8217;ll use <a href=\"https:\/\/reqres.in\/\">ReqRes<\/a> and just grab a user with <code>GET https:\/\/reqres.in\/api\/users\/2<\/code>.<\/p>\n<pre>{\"data\":{\"id\":2,\"email\":\"janet.weaver@reqres.in\",\"first_name\":\"Janet\",\"last_name\":\"Weaver\",\"avatar\":\"https:\/\/reqres.in\/img\/faces\/2-image.jpg\"},\"support\":{\"url\":\"https:\/\/reqres.in\/#support-heading\",\"text\":\"To keep ReqRes free, contributions towards server costs are appreciated!\"}}<\/pre>\n<p>And now, some code!<\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/getSomeJSON.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/getSomeJSON.png\" alt=\"\" width=\"432\" height=\"691\" class=\"aligncenter size-full wp-image-4395\" \/><\/a><\/p>\n<p><a href=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/jsonResponse.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2021\/08\/jsonResponse.png\" alt=\"\" width=\"557\" height=\"95\" class=\"aligncenter size-full wp-image-4399\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It has been nearly 6 years since Apple first open sourced the Swift language and brought it to Linux. In that time we&#8217;ve seen the rise (and sometimes fall) of server-side frameworks such as Zewo, Kitura, and Vapor as well as porting Swift to SBC devices such as the Raspberry Pi and Beaglebone. I recently [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,19,5,71],"tags":[],"class_list":["post-4386","post","type-post","status-publish","format-standard","hentry","category-apple","category-linux","category-swift","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/4386"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=4386"}],"version-history":[{"count":10,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/4386\/revisions"}],"predecessor-version":[{"id":4400,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/4386\/revisions\/4400"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=4386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=4386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=4386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}