Swift is one of the most recent and feature-rich functional programming language. It is developed by Apple engineers. In this quick guide, You will learn how to set up Swift on Linux.

The swift package also comes with Swift REPL tool. We can use the tool to quickly execute swift snippets.

Currently, Swift is only supported for Ubuntu and Mac OS. If you are planning to learn this juicy language then you need to setup Switf on your Linux computer system.

Downloading Swift language package

To setup Swift language on Linux. We need to download the Swift package which we will configure in our environment variable. Then we can easily compile and run Swift programs.

Download Swift Package

After downloading the package file, simply extract it and rename it to Swift for the convenience.

Set up and configure Swift on your Linux distribution

We need to add the path of this extracted folder to the environment variable. This can be done in two ways.

Method 1: If you want to set up Swift for all the users then move the Swift folder to /opt/ folder. Add the path of this Swift folder in /etc/environment file and save it.

Setting up the Swift environment variable

Now just logout and login again and type swift –version in the terminal. This will output the currently configured Swift details.

Checking the swift version and status

Method 2: Another way to set up Swift for a particular user is that you can place the Swift folder in the user directory that was extracted and renamed earlier.

In my case it’s here : /home/takshaksh/Swift. Now simply echo the environment folder in /home/takshaksh/.bashrc file.

If this file is not available in your distribution then simply create one and don’t forget to add β€œ.” a dot before the file name as it denotes that it’s a hidden file. This file gets executed every time when you start the terminal.

Add the below line at the end of the file. Here takshaksh is the username so replace it with yours.

export PATH=/home/takshaksh/Swift/usr/bin:"${PATH}"

Running a swift program using CLI

let name = "Hello World from Ubuntu !!"

Create a file and place the above swift code in it and save it as HelloSwift.swift

Running Swift program using command line

Alternatively, For a step-by-step video guide


That is how you can set up and run Swift programs on Linux. Let us know your thoughts in the comment section below. Do you think Swift is the best programming language out there?