How to Install Swift Programming Language on Ubuntu 20.04 LTS


In this article, I will take you through the steps to install Swift Programming Language on Ubuntu 20.04 LTS. Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community. Initially it was developed as a replacement for Apple earlier programming language called Objective C but since 2015, it was made as open source software under Apache License 2.0. Now it can be used for both Apple as well as Linux Platform.

Swift provides a modern approach to safety and performance which makes it a easy choice for Developers to create range of mobile and desktop apps. There are multiple different ways to install swift programming language on Ubuntu 20.04 LTS but here we will see the most simplest and recommended approach. So without any further delay, let's dive right in and see the steps to install swift programming language on below section.

How to Install Swift Programming Language on Ubuntu 20.04 LTS

How to Install Swift Programming Language on Ubuntu 20.04 LTS

Also Read: How to Install Grafana Monitoring Tool on Ubuntu 20.04 LTS [Best Steps]

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt, tar and wget utility installed in your Server.


Step 2: Update Your Server

In the very first step, you need to update your Server by using apt update command. This will download and install all the latest available versions from configured Ubuntu Repo.


Please note that here I am using root user to run all the below commands. You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.
root@localhost:~# apt update
Hit:1 focal InRelease
Hit:2 focal InRelease
Hit:3 stable InRelease
Hit:4 focal-pgdg InRelease
Hit:5 focal InRelease
Hit:6 focal-updates InRelease
Hit:7 focal-backports InRelease
Hit:8 focal InRelease
Get:9 focal-security InRelease [114 kB]
Hit:10 stable InRelease
Get:11 focal-security/main amd64 DEP-11 Metadata [29.0 kB]
Get:12 focal-security/universe amd64 DEP-11 Metadata [63.9 kB]
Get:13 focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]


Step 3: Download Swift Package

You can go to Swift official Download Page and download the latest swift package using wget utility as you can see below. This will download the package in local system directory. If you want to ignore all the below output then you can use -q option to run it quietly and to just show the status at the end.

root@localhost:~# wget
--2021-10-28 12:38:30--
Resolving ( 2403:300:a06:f000::3, 2403:300:a06:f000::1,, ...
Connecting to (|2403:300:a06:f000::3|:443... failed: Connection timed out.
Connecting to (|2403:300:a06:f000::1|:443... failed: Connection timed out.
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 578403385 (552M) [application/octet-stream]
Saving to: ‘swift-5.5.1-RELEASE-ubuntu20.04.tar.gz’

swift-5.5.1-RELEASE-ubuntu20.04.tar.gz 100%[============================================================================>] 551.61M 11.1MB/s in 52s

2021-10-28 12:43:45 (10.7 MB/s) - ‘swift-5.5.1-RELEASE-ubuntu20.04.tar.gz’ saved [578403385/578403385]


Step 4: Extract Package

In the next step you need to extract the swift package using tar utility. But first you need to create a directory called swift under /usr/share path using mkdir /usr/share/swift command as shown below. You can choose any location to store your extracted swift package files based on your requirement.

root@localhost:~# mkdir /usr/share/swift

Then extract the package using tar -xvf swift-5.5.1-RELEASE-ubuntu20.04.tar.gz -C /usr/share/swift command as shown below.

root@localhost:~# tar -xvf swift-5.5.1-RELEASE-ubuntu20.04.tar.gz -C /usr/share/swift


Step 5: Export Binary Path

To enable swift command line tools, you need to export the binary path to current logged in user .bashrc file using below export command. This will enable the system wide visibility of swift command line tools. Then refresh .bashrc file using source ~/.bashrc command.

root@localhost:~# echo "export PATH=/usr/share/swift/swift-5.5.1-RELEASE-ubuntu20.04/usr/bin/:$PATH" >> ~/.bashrc
root@localhost:~# source ~/.bashrc


Step 6: Check Swift Version

If you want to confirm the installation of swift package, then you need to use swift --version command. As you can see, current installed version is 5.5.1.

root@localhost:~# swift --version
Swift version 5.5.1 (swift-5.5.1-RELEASE)
Target: x86_64-unknown-linux-gnu


Step 7: Run a Sample Program

It is now time to write a sample program using swift programming language. You can simply run swift on the terminal to open the prompt. Then we are displaying Hi, This is from CyberitHUB on the output using a print statement. Once you are done, you can press Ctrl+D to exit the prompt.

root@localhost:~# swift
Welcome to Swift version 5.5.1 (swift-5.5.1-RELEASE).
Type :help for assistance.
1> print("Hi, This is from CyberitHUB!")
Hi, This is from CyberitHUB!

1 thought on “How to Install Swift Programming Language on Ubuntu 20.04 LTS”

Leave a Comment