Installing Swift on Linux

On MacOS based systems Swift is always present, but Linux based systems may require Swift to be installed. The following is a typical installation process for an Ubuntu system (on a Parallels emulator running on MacOS). It has also been tested successfully on a Fedora based system, although in both cases there is no guarantee that local conditions will prove so amenable as what is described below.

Installing Dependencies

Some dependencies need to be installed before Swift is downloaded. It is worth noting that some flavours of Linux do not need this stage.

~$ sudo apt-get install binutils \ > git \ > gnupg2 \ > libc6-dev \ > libcurl4-openssl-dev \ > libedit2 \ > libgcc-9-dev \ > libpython3.8 \ > libsqlite3-0 \ > libstdc++-9-dev \ > libxml2-dev \ > libz3-dev \ > pkg-config \ > tzdata \ > unzip \ > zlib1g-dev [sudo] password for xxxx: ******** Reading package lists... Done ... Processing triggers for libc-bin (2.35-0ubuntu3.7) ... ~$

The results of running may different depending on the installation. Next load the Swift from the repository at here. Download the appropriate flavour of Swift as well as the signature file. After downloading the Home/Downloads folder should have the following.

$ ls -la Downloads/ total 914168 drwxr-xr-x 3 xxxx xxxx 4096 May 9 16:29 . drwxr-x--- 15 xxxx xxxx 4096 May 2 16:49 .. -rw-rw-r-- 1 xxxx xxxx 592835466 May 2 16:57 swift-5.10-RELEASE-ubuntu22.04-aarch64.tar.gz -rw-rw-r-- 1 xxxx xxxx 819 May 9 16:29 swift-5.10-RELEASE-ubuntu22.04-aarch64.tar.gz.sig ~$

If this is the first time downloading Swift packages, import the PGP keys into the keyring. Go to the Home/Downloads folder and run the following.

~/Downloads$ wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - gpg: directory '/home/hsfr/.gnupg' created gpg: keybox '/home/hsfr/.gnupg/pubring.kbx' created gpg: /home/hsfr/.gnupg/trustdb.gpg: trustdb created gpg: key D441....B37AD: public key "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>" imported gpg: key 9F59....A56D5F: public key "Swift 2.2 Release Signing Key <swift-infrastructure@swift.org>" imported ... gpg: key 925C....3D1561: "Swift 5.x Release Signing Key <swift-infrastructure@swift.org>" 1 new signature gpg: key F167....9CE069: "Swift Automatic Signing Key #4 <swift-infrastructure@forums.swift.org>" 1 new signature gpg: Total number processed: 11 gpg: imported: 8 gpg: new signatures: 3 ~/Downloads$

Note that the key values will be different for your installatiopon.

~/Downloads$ gpg --keyserver hkp://keyserver.ubuntu.com --refresh-keys Swift gpg: refreshing 8 keys from hkp://keyserver.ubuntu.com gpg: key F167....9CE069: "Swift Automatic Signing Key #4 <swift-infrastructure@forums.swift.org>" not changed gpg: key FAF6....C16FEA: "Swift Automatic Signing Key #3 <swift-infrastructure@swift.org>" not changed gpg: key 925C....3D1561: "Swift 5.x Release Signing Key <swift-infrastructure@swift.org>" not changed gpg: key 7638....B2B08C4: "Swift Automatic Signing Key #2 <swift-infrastructure@swift.org>" not changed gpg: key EF54....1E1B235: "Swift 4.x Release Signing Key <swift-infrastructure@swift.org>" not changed gpg: key 63BC....1D306C6: "Swift 3.x Release Signing Key <swift-infrastructure@swift.org>" not changed gpg: key 9F59....1A56D5F: "Swift 2.2 Release Signing Key <swift-infrastructure@swift.org>" not changed gpg: key D441....12B37AD: "Swift Automatic Signing Key #1 <swift-infrastructure@swift.org>" not changed gpg: Total number processed: 8 gpg: unchanged: 8 ~/Downloads$

Now extract the tar file.

~/Downloads$ tar xvf swift-5.10-RELEASE-ubuntu22.04-aarch64.tar.gz swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/ swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/bin/ swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/bin/clang ... swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/share/swift/diagnostics/en.strings swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/share/swift/features.json swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/share/swift/LICENSE.txt ~/Downloads$

Once the files have been extracted, set up the path to the binaries. There is a usr/bin directory in the extracted directory. First of all move this to a new location in the /usr/local/swift directory.

~/Downloads$ sudo mkdir /usr/local/swift [sudo] password for hsfr: ******** ~/Downloads$ sudo mv swift-5.10-RELEASE-ubuntu22.04-aarch64/usr/ /usr/local/swift ~/Downloads$ \

Add this to the PATH environment.

~/Downloads$ echo 'export PATH=/usr/local/swift/usr/bin:$PATH' >> ~/.bashrc ~/Downloads$

At this point the Swift environment should be loaded so test using

~/Documents/SoftwareDevelopment/Public_Packages/CRexsel$ swift --version Swift version 5.10 (swift-5.10-RELEASE) Target: aarch64-unknown-linux-gnu ~/Documents/SoftwareDevelopment/Public_Packages/CRexsel$ swift Welcome to Swift! Subcommands: swift build Build Swift packages swift package Create and work on packages swift run Run a program from a package swift test Run package tests swift repl Experiment with Swift code interactively Use `swift --version` for Swift version information. Use `swift --help` for descriptions of available options and flags. Use `swift help <subcommand>` for more information about a subcommand. ~/Documents/SoftwareDevelopment/Public_Packages/CRexsel$

Before the uncompile option of CRexsel can be run the xsltproc command must be installed (on some Linux distrobutions it may already be present).

~/Documents/SoftwareDevelopment/Public_Packages/CRexsel$ sudo apt-get install xsltproc Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: xsltproc 0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded. Need to get 14.8 kB of archives. After this operation, 159 kB of additional disk space will be used. ... Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. ~/Documents/SoftwareDevelopment/Public_Packages/CRexsel$

This should be sufficient to install and run CRexsel.

Copyright 2024 Hugh Field-Richards. All Rights Reserved.