How to install Swift on Ubuntu

Apple Inc. just announced its new programming language, Swift, to be open source. As a new programming language, it quickly becomes very popular as one of the fastest growing programming language in history. By making it open source, community around the world can help to make it available everywhere.

At the time of this writing, it is still in development snapshot stage meaning it is not official release yet and available for both Apple platform and Linux (Ubuntu 14.04 and Ubuntu 15.10).

How to install Swift on Ubuntu

This article will show you how to install Swift on Ubuntu. If you use Ubuntu Linux version 14.0 or 15.10 you can follow the installation guide available on the official Swift website. I try to make it simpler and quicker way to install and run Swift on Ubuntu. After you install the required dependency packages, importing PGP key, and download the package you need to extract the package and add swift into system PATH.

$ tar zxf swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10.tar.gz 
$ mv swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10 swift
$ export PATH=$PATH:/home/fuad/swift/usr/bin

As you can see in the command above, I renamed swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10 directory/folder to swift to make it short. In the export command, rename the /home/fuad/ with yours.

Now swift should be in your system PATH and is ready.

$ swift
Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
  1> let message = "Hello Swift!!"
message: String = "Hello Swift!!"
  2> print(message)
Hello Swift!!
  3> :q

Type :q to quit from Swift. Below is the screenshot.

Swift Programming Language on Ubuntu

Note:

The PATH will reset to default after system reboot  or closing the Terminal application. To make it permanent, you need to add it into .profile file in your $HOME directory like in the image below

Set Swift on system path

  • Sadat Duraki

    I follow your instructions for last step, but after I reboot or close terminal, swift doesn’t work.

    • Have you added the swift PATH into $HOME/.profile file? What is the error message?

      • Sadat Duraki

        I’ve write if [ -d “$HOME/bin” ] ; then
        PATH=”$HOME/bin:$PATH”
        fi
        export PATH=$PATH:/home/sadat/swift-DEVELOPMENT-SNAPSHOT-2016-02-25-a-ubuntu14.04/usr/bin
        There is no error message.

        • So how do you know that swift doesn’t work after reboot if there is no error message? When you type “echo $PATH”, the /home/sadat/swift-PATH/usr/bin is already in your $PATH?

          • Sadat Duraki

            When I open new terminal and type : swift , I get this message “The program ‘swift’ is currently not installed. You can install it by typing:
            sudo apt-get install python-swiftclient”. I’m newbie to linux.

          • This is the error message that I had asked it about. python-swiftclient is SwiftStack tool, not the Apple Swift that we are talking about. Please ensure that the $PATH is correctly configured. Please post ‘echo $PATH’ here!

          • Sadat Duraki

            /home/sadat/.rvm/gems/ruby-2.3.0/bin:/home/sadat/.rvm/gems/ruby-2.3.0@global/bin:/home/sadat/.rvm/rubies/ruby-2.3.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/sadat/.rvm/bin:/home/sadat/.rvm/bin

          • Sadat Duraki

            Sir, can you give me step by step instructions for configuring $PATH?

  • Great, that’s working well. I use Linux Mint 17. Well, that’s almost Ubuntu 14. Thanks. Does it come with a GUI and simulator for iPad too? Nah, still have to buy an Apple comp I’m afraid. But now we can start using Swift!

    • Hi Nils, the answer is NO. We can write Swift codes on Linux or Windows, but we still need an Apple system if we want to develop iOS/OSX apps, at least up until now.