“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
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
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
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
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
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