Swift is a general purpose, compiled programming language that has been developed by Apple for macOS, IOS, watchOS, tvOS and for Linux as well. Swift offers better security, performance & safety & allows us to write safe but strict code. Swift is also very easy to learn & has been compared to Python in terms of ease of learning & there are also plenty of resources available online to learn Swift, which also makes is more approachable.
As of now, Swift is only available for installation on Ubuntu for Linux platform. So in this tutorial, we are going to discuss how to install Swift on Linux, or to be more precise how to Install Swift on Ubuntu.
So let’s start with the dependencies that are required to be installed on Ubuntu systems before we actually install Swift on Ubuntu.
(Recommended Read: GoLang: Install Go on CentOS (RHEL, Oracle Linux) )
(Also Read: Learn to install PYTHON 3.6 on CentOS 7 )
install SWIFT on Linux
Install Dependencies
Three packages are required to be installed on Ubuntu systems to be able to install & use Swift. These packages are ‘clang, libicu-dev, & git’ . Install these packages from the terminal using the following command,
$ sudo apt-get install clang libicu-dev -y
We are now ready to install Swift on our Linux machines.
Download the Swift packages
We will need to download Swift packages from the official website. Package for Swift are available for Ubuntu 14.04, 16.04 & 16.10. Using the command (applicable to your OS) mentioned below , download the swift package,
Ubuntu 14.04
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1404/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu14.04.tar.gz
Ubuntu 16.04
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1604/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu16.04.tar.gz
Ubuntu 16.10
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1610/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu16.10.tar.gz
Extract Package
Now we will extract the downloaded package into a folder in our home directory (you can use another directory),
$ mkdir ~/swift
$ tar -xvzf swift-4.1-RELEASE-ubuntu16.04.tar.gz -C ~/swift
Next step is to configure the environment variables on the system.
Configuring environment variables
We need to configure PATH variable in our .basrc file as this will be required to execute the programs. So open .basrc & make the following entry into the file,
$ sudo nano ~/.bashrc
export PATH= /home/dan/swift/swift-4.1-RELEASE-ubuntu16.04/usr/bin:$PATH
& run ,
$ source .bashrc
That’s it, we now have swift installed & ready to use.
Checking Swift
To make sure that swift has been installed properly, open the terminal & run the following command to check the swift version,
$ swift --version
If there were no issues with the installation, it should provide you with the installed Swift version
This completes our tutorial on how to install Swift on Linux systems.Please feel free to send in any questions or queries using the comment box below.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Donate us some of your hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.
how to install it in other distro? like fedora or openSUSE (rpm based)
thanks in advance
Official RPMs are still not available but you can try to build with source. You can try following link , maybe it will help,
https://github.com/FedoraSwift/fedora-swift