Install and Configure Swift on Arch Linux for CLion
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:
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.
- Swift to root that you can modify the
/usr
folder:sudo su
- Go to Lib folder:
cd /usr/lib/
- Create a
swift-clion
folder and ausr
folder in it:mkdir -p swift-clion/usr
- Mount the old to the new folder:
mount --bind /usr/lib/swift/ /usr/lib/swift-clion/usr/
- 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 File
→ Settings
→ Plugins
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 File
→ Settings
→ Build, Execution, Deployment
→ Swift
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
- Open fstab file as root:
vim /etc/fstab
- 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!
[1] JetBrains: CLion IDE (https://www.jetbrains.com/de-de/clion/download/)
[2] Swift for Linux (2018): http://swift-linux.refi64.com/en/latest/install.html
[3] Mount-Manpage: http://manpages.ubuntu.com/manpages/cosmic/man8/mount.8.html