Install Swift 5.0 on Ubuntu 18.04

This page is a personal memo about how to install Swift 5.0 on Ubuntu 18.04.
This memo is written in APR 2019.

1. Install “clang”

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

sudo apt-get install clang

2. Install “libcurl3”, “libpython2.7”, and “libpython2.7-dev”

Before installing swift, “libcurl3”, “libpython2.7”, and “libpython2.7-dev” is needed to install on Ubuntu 18.04 for Swift installer running.
Run the following code.

sudo apt-get install libcurl3 libpython2.7 libpython2.7-dev

3. Get Swift tar file for Ubuntu 18.04

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

By using “wget” command, download the Swift tar file for Ubuntu18.04 from the above page. (Noted swift-5.0 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.0-release/ubuntu1804/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu18.04.tar.gz

4. Extract the downloaded “tar” file

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

tar xzf swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu18.04.tar.gz

5. Move the extracted files

Move the extracted file to the user’s “share” directory.

sudo mv swift-5.0-RELEASE-ubuntu18.04 /usr/share/swift

6. Config to system’s PATH environment variable

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

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

Then, use “source” command to reload “~/.bashrc”.

source  ~/.bashrc

7. Check the install successfully

01. Check the Swift version.

swift --version

If the install is successful, the output is like below…

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

02. Run the Swift REPL

Run the Swift REPL in Ubuntu terminal. Just type “swift” and push the return button.

swift

If the install is successful, the Swift REPL is also run like below…

When quite the REPL, run the “:exit” command.

> :exit

--

--

iOS Developer, Front-end Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store