Swift is a modern, fast, and powerful general-purpose programming language. Mainly it is used for iOS app development but, you can use it for systems programming, cloud services, and design other applications. Powerful error handling and Advanced control flow are some of the features of this language.
Other features include,
- Closures unified with function pointers
- Tuples and multiple return values
- Fast and concise iteration over a range or collection
- Structs that support methods, extensions, and protocols
- Functional programming patterns, e.g., map and filter
- Compiled and optimized to get the most out of modern hardware
- Type inference and pattern matching with a modern, lightweight syntax
- Easier to write, read and maintain as well.
Let’s install Swift on Ubuntu Linux.
Install Swift on Ubuntu 20.04
Swift needs the below software/library to run properly. You need to install them as sudo user.
$ sudo apt-get install \ binutils \ git \ gnupg2 \ libc6-dev \ libcurl4 \ libedit2 \ libgcc-9-dev \ libpython2.7 \ libsqlite3-0 \ libstdc++-9-dev \ libxml2 \ libz3-dev \ pkg-config \ tzdata \ zlib1g-dev
Swift is available for multiple platforms from Apple Xcode to Ubuntu, CentOS, Windows, Amazon Linux. You can download it from here.
Here we are interested in Ubuntu, so depending on your Ubuntu version, download the Swift installer. You can also download a development snapshot if you want to contribute to the development of the language.
Go to the Downloads folder and extract the tar archive using the command given below.
$ tar xzf swift-<VERSION>-<PLATFORM>.tar.gz
In my case it is,
$ tar xzf swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
Move the extracted file either /user/share/swift or /opt/swift directory. That’s it and your swift installation is complete.
sudo mv swift-5.3-RELEASE-ubunutu20.04 /usr/share/swift
Update system PATH environment variable
echo "export PATH=/usr/share/swift/usr/bin:$PATH" >> ~/.bashrc source ~/.bashrc
Just type below on terminal check installation.
Output Swift version 5.3.3 (swift-5.3.3-RELEASE) Target: x86_64-unknown-linux-gnu /usr/share/swift/usr/bin/lldb "--repl=-disable-objc-interop -color-diagnostics" Welcome to Swift version 5.3.3 (swift-5.3.3-RELEASE). Type :help for assistance. 1>
You can’t install Xcode on Ubuntu Linux as it is not available for any Linux Distributions as of today. But, you can always install Swift on Linux and learn App Development
Go ahead install swift and start learning it.