In this tutorial, we will show you how to install Swift Programming Language on Ubuntu 22.04 LTS. Swift, the versatile and efficient programming language developed by Apple, has gained widespread popularity in the software development world. While it’s commonly associated with iOS and macOS app development, Swift has made its mark as a robust choice for server-side applications and beyond.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Swift Programming Language on Ubuntu 22.04. You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Swift.
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Swift Programming Language on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. Begin by updating the package lists to make sure you have the most recent information about available software. Open your Terminal and run:
sudo apt update sudo apt upgrade
Step 2. Installing Required Dependencies,
Swift relies on specific dependencies, such as Clang and libicu. You can install them using the following command:
sudo apt install clang libicu-dev
To ensure that these dependencies have been successfully installed, you can verify their versions. Run the following command to check the Clang version:
Step 3. Installing Swift Programming Language on Ubuntu 22.04.
Now that your system is ready, you can proceed with downloading Swift. The process involves choosing a Swift version and acquiring the necessary tarball:
Create a directory where Swift will be installed. You can choose a location based on your preferences, but
/opt/swift is a common choice:
sudo mkdir /opt/swift
Extract the downloaded Swift tarball into the directory you created. This ensures that the Swift executable and libraries are placed in the right location:
sudo tar -xzf swift-5.9.1-RELEASE-ubuntu22.04.tar.gz -C /opt/swift --strip-components=1
To conveniently run Swift from any directory, you need to add Swift to your system’s PATH. Open your
.zshrc file using a text editor and add the following line:
After making this change, apply it by running:
Alternatively, for the Zsh shell:
Confirm that Swift is installed correctly by running the following command:
This command will display the Swift version and other relevant information, indicating that Swift is successfully set up on your system.
Step 4. Troubleshooting.
Even with a well-defined installation process, you might encounter issues. Here are some common problems and their solutions:
Common Installation Issues
- Dependency Issues: Ensure that the required dependencies, such as
libicu-dev, are installed correctly.
- Incorrect Version Downloads: Double-check that you’ve downloaded the Swift version compatible with your Ubuntu 22.04 system.
- PATH Configuration Errors: Verify that you’ve correctly added Swift to your system’s PATH.
Congratulations! You have successfully installed Swift. Thanks for using this tutorial for installing the Swift Programming Language on the Ubuntu system. For additional help or useful information, we recommend you check the official Swift website.