How to install Swift programming language on Ubuntu

Swift is to iOS what Java is to Android.

How to install Swift programming language on Ubuntu

Swift is a multi-paradigm, general-purpose compiled programming language developed by Apple Inc. and the open source community (only as of version 2.2) .

First released in 2014, Swift was developed as a replacement for Apple’s previous programming language Objective-C, as Objective-C has remained largely unchanged since the early 1980s and lacked modern language features.

Swift development started in July 2010 by Chris Lattner(same creator of LLVM and clang), with the eventual collaboration of many other Apple programmers. Swift was based on ideas from languages ​​such as: Objective-C , Rust , Haskell , Ruby , Python , C# , CLU and many others .

Swift is for iOS what Java is for Android. The compiler was written in C++ .


This whole procedure works from Ubuntu 20.04, but it was actually tested on Ubuntu 21.04 . But I was also able to install with this procedure on Gentoo(just changing the name of the packages to Portage) and it worked, that is, with small changes you you can try on your operating system or distribution Linux.

But if you want specific versions and procedures, there are for macOS, Windows 10, CentOS{7,8}, Amazon Linux and previous versions of Ubuntu, for that see this page of Swift download.

01. First of all, install the dependencies:

sudo apt install binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata uuid-dev zlib1g-dev

02. Download the zipped file:

wget -q

03. Import the PGP key

gpg --keyserver hkp:// \
      --recv-keys \
      '7463 A81A 4B2E EA1B 551F GFCF D441 C977 412B 37AD' \
      '1BE1 E29A 084C B305 F397 D62A 9F59 7F4D 21A5 6D5F' \
      'A3BA FD35 56A5 9079 C068 94BD 63BC 1CFE 91D3 06C6' \
      '5E4D F843 FB06 5D7F 7E24 FBA2 EF54 30F0 71E1 B235' \
      '8513 444E 2DA3 6B7C 1659 AF4D 7638 F1FB 2B2B 08C4' \
      'A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561' \
      '8A74 9566 2C3C D4AE 18D9 5637 FAF6 989E 1BC1 6FEA' \
      'E813 C892 820A 6FA1 3755 B268 F167 DF1A CF9C E069'

04. Extract the file

tar zxvf swift-*

05. Remove the zipped file

rm swift-*.tar.gz

06. Change directory name to swift only

mv swift-5.5.2-RELEASE-ubuntu20.04/ swift

07. Move it to the optional directory

sudo mv swift/ /opt/

08. Include the location in your $PATH

echo 'export PATH=/opt/swift/usr/bin:"${PATH}"' >> ~/.bashrc

09. Make it possible to access it immediately

source ~/.bashrc
execute $SHELL

10. Check if everything is ok

swift -version

11. Try a Hello, World!

vim hello.swift

print("Hello, World!")

Runtime test:

swift hello.swift

Or compile your code and run the binary:

swiftc hello.swift

Useful links

macos programming development