Swift Language: How to easily install SWIFT on Linux
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
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,
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1404/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu14.04.tar.gz
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1604/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu16.04.tar.gz
$ wget https://swift.org/builds/swift-4.1-release/ubuntu1610/swift-4.1-RELEASE/swift-4.1-RELEASE-ubuntu16.10.tar.gz
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.
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.