Skip to content

Instantly share code, notes, and snippets.

@izinin
Forked from Jswizzy/InstallingSwift.md
Created May 15, 2022 13:25
Show Gist options
  • Save izinin/c9bc70622aad2bdcea35ac2508b71b4f to your computer and use it in GitHub Desktop.
Save izinin/c9bc70622aad2bdcea35ac2508b71b4f to your computer and use it in GitHub Desktop.
Swift Install Instruction 20.04

Installing Swift on Ubuntu 20.04

1. Install Depencies

“clang”[ˈklæŋ] is the compiler based on LLVM for C, C++, Objective-C, and Objective-C++. clang is needed to install in order to Swift. Run the following code in Ubuntu terminal.

Before installing swift “libpython2.7” and “libpython2.7-dev” are needed to get Swift running. Run the following code.

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

2. Download Swift tar for Ubunutu 20.04

There is a source code in Swift documentation page. Swift.org — Download Swift

By using “wget” command, download the Swift tar file for Ubuntu20.04 from the above page. (Noted swift-5.3 is the newest version when this article is published.) Before running the below code, change to the directory which you want to download by using “cd” command. And then, run the following code.

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

3. Extract the downloaded "tar" file

By using “tar” command, expand the downloaded archive file.

x = extract/unzip z= gunzip format f= file

tar xzf swift-5.3-RELEASE-ubuntu20.04.tar.gz

4. Move the extracted files

Move the extracted file to the user’s “share” directory. A good place to put applications.

sudo mv swift-5.3-RELEASE-ubuntu20.04 /usr/share/swift

5. Add to system PATH enviroment variable

Set the Swift path on the system’s PATH environment variable.

note: If using bash change ~/.zshrc to ~/.bashrc

echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.zshrc
source ~/.zshrc

6. Check Install successful

Check Version

swift -v

if successful

Swift version 5.3 (swift-5.3-RELEASE)
Target: x86_64-unknown-linux-gnu

run the REPL

swift

if successful the swift REPL will run

to quit the REPL, run the ":exit" command

> :exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment