Install and Configure Swift on Arch Linux for CLion

Max Großmann
4 min readOct 16, 2020
Photo by Maxwell Nelson on Unsplash

In this article i want to show how to install swift on Arch Linux and integrate it in the CLion IDE¹.

Swift Toolchain Installation

First you have to install the swift-Package.

There are multiple aur packages available:

  • swift: Builds swift from source²
  • swift-bin: Uses a patched version of the ubuntu binaries$²

I prefer using the swift-bin aur over swift aur, because of faster installation and update times. (I don’t have to build the complete swift binaries from source)

yay -S swift-bin

Locate swift toolchain location

When installing the swift-bin aur, the path of the toolchain will be /usr/lib/swift.

In this folder you can find all binaries and libraries that you need for running a swift script.

> ls /usr/lib/swift                                                                                                                                                                                     
bin include lib local share

The Problem with CLion

As for now (Oct. 2020) there is one Problem.

CLion does only recognizes the toolchain path, when the folder directly above bin, include, lib, ... is excaclty named usr.

Fix the Problem

To fix this problem we will create another folder in /usr/lib/ named swift-clion and place an usr folder in it. Then we are going to mount the /usr/lib/swift to /usr/lib/swift-clion/usr so that the needed subdirectories (bin, include, lib, ...) are directly placed below the usr folder.

  1. Swift to root that you can modify the /usr folder: sudo su
  2. Go to Lib folder: cd /usr/lib/
  3. Create a swift-clion folder and a usr folder in it: mkdir -p swift-clion/usr
  4. Mount the old to the new folder: mount --bind /usr/lib/swift/ /usr/lib/swift-clion/usr/
  5. Reload the current folder: cd .

Update 2022: Sumeet in the comments highlighted, that is is also possible to use symlinks instead of mounts.

Verify the new folder structure

> tree /usr/lib/swift-clion/ -L 2
/usr/lib/swift-clion/
└── usr
├── bin
├── include
├── lib
├── local
└── share

Configure CLion

Install swift Plugin

Open FileSettingsPlugins and install the Swift-Plugin (developed by JetBrains) from Marketplace.

Then click OK. You may restart CLion, so that the Swift-Plugin is installed completely.

Configure Swift-Toolchain

Open CLion and go to FileSettingsBuild, Execution, DeploymentSwift

Under toolchain path, write /usr/lib/swift-clion.

You should see Toolchain version 5.X below the textfield.

Click ok and restart CLion to save the changes.

Test CLion with a new Project

Create a new Swift-Executable Package.

Open and modify the main.swift file the Sources Folder.

e.g.

print("Hello, swift!")

Execute the program with the green Play-Button or Shift+F10

You should now see, that the small hello world program is working.

Persist mount

When we restart our pc, the mount point for the swift-clion toolchain will be gone.

To mount the folder again, when the system boots, we have to add an entry to the /etc/fstab

  1. Open fstab file as root: vim /etc/fstab
  2. Add the following line, save and quit the editor:
/usr/lib/swift/ /usr/lib/swift-clion/usr/ none rw,bind 0 0

3. mount -a

Thanks for reading!

Clap, if you enjoyed it!

--

--