Episode #214

Swift on Linux

16 minutes
Published on March 28, 2016

This video is only available to subscribers. Get access to this video and 584 others.

In this episode we talk a look at the cool new world of open source Swift! We'll use vagrant to spin up a Linux virtual machine, then install the latest Swift development snapshot and talk about running the Swift REPL and compiling programs on Linux. Using the latest development snapshot is not without its troubles, however, so you'll see how best to report bugs and/or look for workarounds. Enjoy!

Note that the snapshot version that I install in this video is already out of date. Make sure to use the latest snapshot URL in the script below.

Episode Links

Vagrant Setup

First, install vagrant, then run vagrant init to get a Vagrantfile in the current directory. Then you can change it to:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.ssh.pty = true

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get install -y git clang libicu-dev

    wget INSERT_SNAPSHOT_URL
    tar xzvf INSERT_SNAPSHOT_FILENAME

    echo "export PATH=/home/vagrant/INSERT_SNAPSHOT_DIR/usr/bin:$PATH" >> ~/.profile

    # this workaround was only necessary in the 3/16 snapshot. Later snapshots have fixed the issue.
    echo "export LD_LIBRARY_PATH=/home/vagrant/INSERT_SNAPSHOT_DIR/usr/lib/swift/linux/:$LD_LIBRARY_PATH" >> ~/.profile

    swift --version
  SHELL
end

This episode uses Swift dev-2016-03-16a, Vagrant 1.8.5.