How to Install Swift Programming Language on Debian 11 Bullseye

Swift, often referred to as “Objective-C, without the C,” is an open-source programming language developed and maintained by Apple. Swift is a general-purpose programming language built using modern safety, performance, and software design patterns. The Swift project aims to create the best available language for systems programming to mobile and desktop apps, scaling up to cloud services.

In the following tutorial, you will learn how to install Swift on Debian 11 Bullseye.


  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo privilages or root access (su command).
  • Required Packages: wget

Updating Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade

Root or Sudo Access

By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.

Install Python 3.8

To use Swift on Debian 11, you will need to install Python 3.8. As this is not available in Debian 11 default library, you will need to compile from scratch, but the process is very straightforward. You will need to visit the Python official download page to get the latest version; at the time of the creation of this guide, it is 3.8.12, but in time this will change, make sure to keep checking for updates in the future and repeating this process.

Once you have got the download link, use the wget command to download the Python 3.8 archive:


Extract the Python archive. Remember, change the version number if you downloaded a newer one:

tar -xf Python-3.8.12.tar.xz
mv Python3.8.12 /opt/Python3.8.12

Now install the dependencies required to install Python 3.8:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev -y

Navigate to the directory and run the ./configure –enable-optimizations command:

cd /opt/Python3.8.12/
./configure --enable-optimizations --enable-shared

Note, The script performs several checks to make sure all of the dependencies on your system are present. The ./configure –enable-optimizations will optimize the Python binary by running multiple tests, which will make the build process slower.

Now that you have built and configured the environment, it is time to compile it with the command make.


A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server. For example, the LinuxCapable server has 6 CPUs, and I can use all 6 or at least use 4 to 5 to increase speed.

make -j 6

Once you have finished building, install Python binaries as follows:

sudo make altinstall

Note, it’s advised to use the make altinstall command NOT to overwrite the default Python 3 binary system.

Next, after the installation, you need to configure the dynamic linker run-time bindings:

sudo ldconfig /opt/Python-3.8.12

Confirm that Python 3.8 is installed and the build version by running the following command:

python3.8 –version

Example output:

Python 3.8.12

Download Swift

Swift has no Debian package available to install; however, to successfully get Swift working in Debian, you can install the Ubuntu package from Swift’s repository, which will work. To download Swift, visit the official download page that has the latest version listed. In time, these will change, but the tutorial will use an example of how to download Swift version build 5.4.2 using the wget command as follows:


Next, run the following command to install the dependencies required:

sudo apt 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 -y

Install Swift

The installation process is relatively quick and easy. First, you will need to extract the archive as follows:

tar -xvzf swift-5.4.2-RELEASE-ubuntu20.04.tar.gz

Next, move the extracted directory to /opt location using the following command:

sudo mv swift-5.4.2-RELEASE-ubuntu20.04 /opt/swift

Next, you will need to download the GPG signature to verify the integrity of the download. To do this, use the following :

wget -q -O - | sudo gpg --import -

Example output if successful:

gpg: Total number processed: 8
gpg:               imported: 7
gpg:         new signatures: 1

Now you need to export the path of the Swift to the .bashrc file as follows:

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

Once the path is exported, you can activate the .bashrc file with the following command:

source ~/.bashrc

To round off the installation, verify the version and build:

swift --version

You should get a similar output:

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

Note, you will need to be logged out of root to use this command.

After the installation, you need to configure the dynamic linker run-time bindings:

sudo ldconfig /usr/swift/lib/python3

Connect to Swift REPL

To connect to the Swift REPLL (Read Eval Print Loop) can be achieved using the following command:


You can write valid Swift statements in this terminal and see them evaluated, and you can even use standard C Libraries by importing the GNU C Libary.

Below are some basic examples of Swift in action:

How to Install Swift Programming Language on Debian 11 Bullseye

To exit the Swift terminal, use the following command:


Comments and Conclusion

In the tutorial, you have learned how to install Swift programming language by downloading and importing the PGP key, extracting the bash and path required, and basic commands to get a feel for the Swift terminal.

Not what you were looking for? Try searching for additional tutorials.

4 thoughts on “How to Install Swift Programming Language on Debian 11 Bullseye”

  1. Joshua,

    Thanks for the guide; build was successful, but unfornately when I attempted the install I got the message “WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv:” … And following that, when I attempted to run “python3.8 –version” I got the reply “python3.8: error while loading shared libraries: cannot open shared object file: No such file or directory.”

    Absent a working Python 3.8 installation, I’m guessing the Ubuntu Swift install will go nowhere. Have you considered trying to tweak the Swift install to use Python 3.9 instead?

    • Hi Frank,

      I forgot the part sudo ldconfig /opt/Python-3.8.12.

      This should fix the issue of the loading of shared libraries, I will add this. Just re-tested this and it works on my end on a fresh Debian 11 installation. For now, I believe we can only use Python 3.8 with Swift from what I have seen unless someone can show me otherwise. The downloaded archive is firstly designed with Ubuntu in mind first, and given the LTS version of Ubuntu 20.04 is 3.8 Debian users can only use 3.8 if this makes sense. I know it is annoying a bit in the extra messing around.

      Let me know if this doesn’t work, check that guide I posted out too unless I have missed something in a detail which is possible only human here.

  2. Joshua, your addition of the “sudo ldconfig…” command worked — though I would like to point out that you have some typos in your modifications to the page: You are denoting the destination of the Python installation in your CLI commands as “Python3.8.12” when it actually needs to include a hyphen, as in “Python-3.8.12″… I managed to work around this but you might want to correct it for the benefit of others. I now have Python 3.8.12 installed and I’m going to proceed to Swift next… Thanks for the quick reply!

    • Awesome to hear, and thanks for pointing out the typo with the missing “-” I have fixed this in the tutorial and my comment reply. Glad it has worked Frank 🙂


Leave a Comment