How To Install Swift On Ubuntu 20.04 LTS

On this tutorial we will learn how to install Swift programming language on Ubuntu 20.04 LTS operating system.

Introduction

Swift is a general purpose, compiled and high-performing programming language with a focus on safety. It was developed by Apple as a replacement for the older Objective-C language. It is very useful for those who want to develop applications for macOS or iOS from Linux. It is a intuitive and friendly programming language to new programmers. It is is optimized for development and performance without compromising on either.
Swift Installation On Ubuntu 20.04

The installation process will be divided into several steps, as follow :

  • Prerequisite
  • Install Swift Dependencies Libraries
  • Download And Extract Swift Source File
  • Testing Swift

Prerequisite

Before we start the Swift installation process on Ubuntu 20.04 LTS, there are prerequisites that must be met, namely:

  • An Ubuntu 20.04 LTS Server with sufficient disk space
  • An account with sudo or root access to run privileged commands
  • Internet access for downloading any required packages





Installing Swift Dependencies Libraries

Swift all required some dependencies need to be installed on our system. We can install all of them using the following command:

$ sudo apt update
$ sudo apt install clang libpython2.7 libpython2.7-dev

The output will be shown below :

mpik@app01:~$ sudo apt install clang libpython2.7 libpython2.7-dev
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following packages were automatically installed and are no longer required:
libevent-core-2.1-7 libevent-pthreads-2.1-7 libmecab2 libzip5 linux-headers-5.4.0-26
linux-headers-5.4.0-26-generic linux-image-5.4.0-26-generic linux-modules-5.4.0-26-generic
linux-modules-extra-5.4.0-26-generic mecab-ipadic mecab-ipadic-utf8 mecab-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
binfmt-support clang-10 lib32gcc-s1 lib32stdc++6 libc6-i386 libclang-common-10-dev libclang-cpp10 libclang1-10
libffi-dev libllvm10 libncurses-dev libobjc-9-dev libobjc4 libomp-10-dev libomp5-10 libpfm4 libtinfo-dev libz3-4
libz3-dev llvm-10 llvm-10-dev llvm-10-runtime llvm-10-tools python3-pygments
Suggested packages:
clang-10-doc ncurses-doc libomp-10-doc llvm-10-doc python-pygments-doc ttf-bitstream-vera
The following NEW packages will be installed:
binfmt-support clang clang-10 lib32gcc-s1 lib32stdc++6 libc6-i386 libclang-common-10-dev libclang-cpp10
libclang1-10 libffi-dev libllvm10 libncurses-dev libobjc-9-dev libobjc4 libomp-10-dev libomp5-10 libpfm4
libpython2.7 libpython2.7-dev libtinfo-dev libz3-4 libz3-dev llvm-10 llvm-10-dev llvm-10-runtime llvm-10-tools
python3-pygments
0 upgraded, 27 newly installed, 0 to remove and 400 not upgraded.
Need to get 85.2 MB of archives.
After this operation, 509 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

...

Setting up clang-10 (1:10.0.0-4ubuntu1) ...
Setting up clang (1:10.0-50~exp1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...

Download And Extract Swift Source File

On this stage, we will download and extracting Swift source file from Switf official website. To do this task, we will be using wget command line.

$ wget https://swift.org/builds/swift-5.4.3-release/ubuntu2004/swift-5.4.3-RELEASE/swift-5.4.3-RELEASE-ubuntu20.04.tar.gz

The output will be as shown below :

mpik@app01:~$ wget https://swift.org/builds/swift-5.4.3-release/ubuntu2004/swift-5.4.3-RELEASE/swift-5.4.3-RELEASE-ubuntu20.04.tar.gz
--2021-09-15 08:07:45-- https://swift.org/builds/swift-5.4.3-release/ubuntu2004/swift-5.4.3-RELEASE/swift-5.4.3-RELEASE-ubuntu20.04.tar.gz
Resolving swift.org (swift.org)... 169.47.73.10
Connecting to swift.org (swift.org)|169.47.73.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 508231331 (485M) [application/x-gzip]
Saving to: ‘swift-5.4.3-RELEASE-ubuntu20.04.tar.gz’

swift-5.4.3-RELEASE-ubuntu20.04.ta 100%[===============================================================>] 484.69M 802KB/s in 10m 23s

2021-09-15 08:18:10 (797 KB/s) - ‘swift-5.4.3-RELEASE-ubuntu20.04.tar.gz’ saved [508231331/508231331]

Make Swift File

After downloading is successfully done, then we will make this file by executing following commands line :

mpik@app01:~$ sudo mv swift-5.4.3-RELEASE-ubuntu20.04 /usr/share/swift
mpik@app01:~$ echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc
mpik@app01:~$ source ~/.bashrc

Then we verify Swift installed on our system by submitting command line :

$ swift -v

The output will be :

mpik@app01:~$ swift -v
Swift version 5.4.3 (swift-5.4.3-RELEASE)
Target: x86_64-unknown-linux-gnu
/usr/share/swift/usr/bin/lldb "--repl=-disable-objc-interop -color-diagnostics"
Welcome to Swift version 5.4.3 (swift-5.4.3-RELEASE).

Testing Swift

On this stage, we will test to use Swift for the first time. Please follow the command line below :

mpik@app01:~$ swift
Welcome to Swift version 5.4.3 (swift-5.4.3-RELEASE).
Type :help for assistance.
1> :help
The REPL (Read-Eval-Print-Loop) acts like an interpreter. Valid statements, expressions, and declarations are immediately compiled and
executed.
The complete set of LLDB debugging commands are also available as described below.
Commands must be prefixed with a colon at the REPL prompt (:quit for example.) Typing just a colon followed by return will switch to the
LLDB prompt.
Type “< path” to read in code from a text file “path”.
Debugger commands:
apropos -- List debugger commands related to a word or subject.
breakpoint -- Commands for operating on breakpoints (see 'help b' for shorthand.)
command -- Commands for managing custom LLDB commands.
disassemble -- Disassemble specified instructions in the current target. Defaults to the current function for the current thread
and stack frame.
expression -- Evaluate an expression on the current thread. Displays any returned value with LLDB's default formatting.
frame -- Commands for selecting and examing the current thread's stack frames.
gdb-remote -- Connect to a process via remote GDB server. If no host is specifed, localhost is assumed.
gui -- Switch into the curses based GUI mode.
help -- Show a list of all debugger commands, or give details about a specific command.
kdp-remote -- Connect to a process via remote KDP server. If no UDP port is specified, port 41139 is assumed.
language -- Commands specific to a source language.
log -- Commands controlling LLDB internal logging.
memory -- Commands for operating on memory in the current target process.
platform -- Commands to manage and create platforms.
plugin -- Commands for managing LLDB plugins.
process -- Commands for interacting with processes on the current platform.
quit -- Quit the LLDB debugger.
register -- Commands to access registers for the current thread and stack frame.
reproducer -- Commands for manipulating reproducers. Reproducers make it possible to capture full debug sessions with all its
dependencies. The resulting reproducer is used to replay the debug session while debugging the debugger.
Because reproducers need the whole the debug session from beginning to end, you need to launch the debugger in
capture or replay mode, commonly though the command line driver.
Reproducers are unrelated record-replay debugging, as you cannot interact with the debugger during replay.
script -- Invoke the script interpreter with provided code and display any results. Start the interactive interpreter if no
code is supplied.

Conclusion

Swift programming language installation is so simple. We have through the Swift installation process on Ubuntu 20.04 LTS operating system. I hope this simple article will be helpful.

Add a Comment

Your email address will not be published. Required fields are marked *