One of the safest and easiest ways to experience Swift 3 on Linux is to use the new Docker for Mac. It includes everything we need to run Linux images on Macs, and Docker also makes it easy to experiment and save checkpoints.
After you’ve signed into the Docker web site and installed Docker for Mac, you can follow these steps to start trying Swift 3 on Linux.
% docker run -t -i --privileged=true ubuntu:14.04 /bin/bash
Then run the following to install some required Ubuntu packages.
apt-get update apt-get install wget -y apt-get install clang libicu-dev libedit-dev python-dev libxml2-dev -y
Now we can install a Swift 3.0 preview (look here for the latest).
wget -qO- https://swift.org/builds/swift-3.0-preview-1/ubuntu1404/swift-3.0-preview-1/swift-3.0-preview-1-ubuntu14.04.tar.gz | tar xz
That unpacks the Swift distribution into a directory at the top of your filesystem (Note that you are running inside the Docker image as
All that’s left is to set your path, and then you can run Swift!
export SWIFT=swift-3.0-preview-1-ubuntu14.04 export PATH=/$SWIFT/usr/bin:$PATH swift Welcome to Swift version 3.0 (swift-3.0-PREVIEW-1). Type :help for assistance. 1> 2+2 $R0: Int = 4 2> ^D
Use Control-D to exit Swift, and then enter Control-D again to exit the Docker image. Now you’re back at your Mac’s terminal prompt.
Where did your image go? You can see your running instance with
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9944aeb00a5d ubuntu:14.04 "/bin/bash" 3 minutes ago Exited (0) 12 seconds ago backstabbing_borg
If you see more than one, look for the one that was created most recently. To save a version of that that you can restart anytime, use
% docker commit 9944aeb00a5d swift
After that, you’ll be able to list your local Docker images:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE swift latest a3f41fe84cbc 3 seconds ago 925.8 MB ... others ...
And now you can run your image anytime with
% docker run -t -i --privileged=true swift /bin/bash
For more information about Swift on Linux, see the Swift Download Docs.