Swift 3.0 for Ubuntu 16.04 Xenial Xerus

| | 4 Comments| 4:17 PM

Swift 3.0

In our zeal to get Swift 3.0 on as many Linux systems as possible we went ahead and got a jumpstart on building for Ubuntu 16.04, also known as Xenial Xerus, for X86 systems. Installation is as easy as using our APT repository with apt-get. Binaries are installed into /opt/swift/swift-3.0, so you will need to update your path after installing the 3.0 package. Editor’s note: For the rationale as to why we use /opt/swift rather than /usr/bin/, see this thread on the swift-dev mailing list.

1. Add the repository key

wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -

2. Add the Xenial repository to sources.list

echo "deb http://iachievedit-repos.s3.amazonaws.com/ xenial main" | sudo tee --append /etc/apt/sources.list

3. Run apt-get update

sudo apt-get update

4. Install swift-3.0!

sudo apt-get install swift-3.0

5. Update that PATH!

export PATH=/opt/swift/swift-3.0/usr/bin:$PATH

6. Try it out

git clone https://github.com/apple/example-package-dealer
cd example-packager-dealer
swift build
Compiling Swift Module 'FisherYates' (1 sources)
Linking Library:  .build/debug/FisherYates.a
Compiling Swift Module 'PlayingCard' (3 sources)
Linking Library:  .build/debug/PlayingCard.a
Compiling Swift Module 'DeckOfPlayingCards' (1 sources)
Linking Library:  .build/debug/DeckOfPlayingCards.a
Compiling Swift Module 'Dealer' (1 sources)
Linking Executable:  .build/debug/Dealer

Run it!



Q. Did Apple build these binaries?
A. No, I built them on my personal server using the instructions I posted here.

Q. What git revisions are included in the build?
A. You can use apt-cache show swift-3.0 to see this information. For example:

# apt-cache show swift-3.0
Package: swift-3.0
Conflicts: swift-2.2
Version: 1:3.0-0ubuntu10+xenial1
Architecture: amd64
Installed-Size: 370463
Maintainer: iachievedit (support@iachieved.it)
Depends: clang (>= 3.6), libicu-dev
Homepage: http://dev.iachieved.it/iachievedit/swift
Priority: optional
Section: development
Filename: pool/main/s/swift-3.0/swift-3.0_3.0-0ubuntu10+xenial1_amd64.deb
Size: 72513864
SHA256: b1bf548f353466ea72696089a8b666956a2603edb467eb0517e858eb1ba86511
SHA1: 5dd02b14d21f2e821040de3bb1052561653fcfcd
MD5sum: f2c3d3b9517a303cc86558b6c560a8d6
Description: Open Source Swift
 This is a packaged version of Open Source Swift 3.0 built from
 the following git revisions of the Apple Github repositories:
       Clang:  460d629e85
        LLVM:  8d0086ac3e
       Swift:  1abe85ab41
  Foundation:  4c15543f82
Description-md5: a6b1dd247c7584b61692a101d9d0e5fa

The source tree is untouched for each build.

Q. Do you test the binaries before you upload them?
A. The Swift build process tests the resulting binaries, and I then do run some basic tests and compile my own applications, but there is currently no separate exhaustive test suite.

Q. Are you releasing builds on a set schedule?
A. Not really, though I may try to stay in sync with the releases from Apple. The idea was to get something out for folks to experiment with and start coding Swift on Linux.

Q. Where is everything installed?
A. Everything gets put in /opt/swift/swift-3.0/usr.

Q. How do I decipher the package version number?
A. This was my first take on what I thought should be an appropriate package version number. Breaking it down, 3.0-0ubuntu10+xenial1 should be:

  • 3.0 is the version of Swift that is packaged
  • -0ubuntu10 indicates that this is the 2nd package for Ubuntu, with the 0 indicating that there is no upstream Debian package upon which this package was based
  • +xenial1 indicates that this package is for Xenial Xerus

I think I got that right, but if you feel otherwise please do drop me a line at support@iachieved.it.

How Does This Work?

I used these awesome instructions on how to host a Debian package repository on Amazon S3. I tried to set up a Launchpad PPA, but quite frankly, got tired of trying to wade through all the metadata required to put together a simple package. I’m sure for hosting distribution repositories it’s all required, but for this it felt like overkill. The folks that develop fpm also have some choice things to say about it.

The packaging scripts we use to build everything and upload to the repository can be found Github. For Swift 3.0 make sure and look at the swift-3.0 branch.

4 thoughts on “Swift 3.0 for Ubuntu 16.04 Xenial Xerus”

  1. After issuing the swift build command on the example I get these errors.

    Is this because of a change from Swift 2 to Swift 3?

    1. Yes, if builidng Apple’s SwiftPM example results in an error it is most likely due to Swift 3 rapidly changing at the end of its release cycle. I’d give it another go with the latest snapshots.

  2. After following these instructions, I got error message error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory which I resolved by running sudo apt-get install libpython2.7.

    Finally, after running the swift commond to play around in the console, I was stuck in the tool until I figured out CTRL+Z exited back to Ubuntu.

Leave a Reply

Your email address will not be published. Required fields are marked *