I have had too many issues trying to run Swift on Ubuntu over the years - mostly the compiler will crash when trying to compile "Hello, World!" program.
Today - in a moment of exasperation I tried using the latest Centos 8 version:
swift-5.5.2-RELEASE-centos8.tar.gz
and surprisingly my project compiled without any warnings or errors.
So if you are using the latest version of Ubuntu 21.10 and you want to try Swift - download the Centos 8 package.
I regularly use Swift on Ubuntu, albeit mostly for (basic) educational stuff.
I've never had any issues with the official releases, but I only ran them on officially supported LTS versions. For the past year, I've been using the packages from https://www.swiftlang.xyz, as they are much easier to install, and support more versions of Ubuntu.
I also thought that sticking to the LTS versions would help, so I did reinstall the OS on my computer using Ubuntu 20.04
Tried hard to get Swift to work and then I gave up and decided to upgrade to 21.10.
No luck again until I installed the Centos 8 package.
Quite a while ago I had v5.11 (I think) working fine then a new version came I "upgraded" - nothing worked. So I went back to v5.11 and every time the new version came out - I will try it and none of them worked.
Then I managed to get 5.3? working and subsequent versions were broken again. I tried official Swift releases, I tried development snapshots, nothing worked ...
Well - I started this thread just to let other people know as a last ditch effort - try the other Linux versions of Swift. There was nothing on the Internet about the crashes I experienced. ( I use many compilers on this machine and everything works fine. )
If you have the option - maybe switch to Centos from Ubuntu.
I use it every day on both M1 (through Parallels) and Intel (VMWare) Ubuntu and through a QEMU virtual server. I use it mostly to make SwiftNIO server apps and a SwiftWASM app using a very similar code base. I have all the regular required packages installed and am usually running the most recent version of Swift compiler and Ubuntu. I haven't experienced any errors in a while. I've had to do fresh installs recently and installed all the required packages freshly (about two-three months ago) and also had no issues getting up and running. I wish I had any advise for what might be going wrong here.
I did clean install of Ubuntu Desktop 20.04.3, tried to get Swift running unsuccessfully. Then upgraded to 21.10 - again no luck with the Swift Ubuntu 20.04 version. Now with the latest CentOS 8 version - everything works fine.
I don't remember having issues with Swift when I was running Ubuntu 16.04 or 18.04.
Oh well - I have now working version, so I am set up.
However after the issues I described I was really wondering if other developers actually use Ubuntu do develop Swift applications.
It would be probably accurate guess that 98% or more of the Swift developers use Mac OS.
My only problem with Ubuntu is that the dependency list isn't actually complete (back in 2019, not sure about now). So when you run any command, you'd be greeted with things like missing libSomethingSomething.so. It was quite annoying finding the right package to install. However, it works smoothly afterward.
I use the official builds of Swift for Ubuntu 20.04 on my Android CI to cross-compile several Swift packages for Android, haven't had a problem. Were you getting missing dependency errors like @Lantua says or was the compiler actually crashing? If you paste your errors here, we could see what the problem is.
eugene@coconut:~$ swift hello.swift
Please submit a bug report (Swift.org - Contributing) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend -frontend -interpret hello.swift -disable-objc-interop -color-diagnostics -new-driver-path /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-driver -resource-dir /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/lib/swift -module-name hello
Swift version 5.5.2 (swift-5.5.2-RELEASE)
While evaluating request ParseSourceFileRequest(source_file "hello.swift")
With parser at source location: hello.swift:1:22
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3efb3]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3ce9e]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3f335]
/lib/x86_64-linux-gnu/libc.so.6(+0x46520)[0x7f35504f2520]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1d45c93]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1d424b9]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1949809]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac4503]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac051c]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abea43]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab911b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab8e0a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab861b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6c71]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6b18]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac8c9a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ad8d2b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abd569]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abd1a3]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab9812]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab9145]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab8e0a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab861b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6c71]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6b18]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae22a0]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae41d4]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1a84f77]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae11d1]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae1cdc]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19cfe84]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19cfb81]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19b823a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19b0bee]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x13d40dd]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x7121c1]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x712471]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5601d0]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x4b140e]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dfd0)[0x7f35504d9fd0]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7d)[0x7f35504da07d]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x4b104e]
Illegal instruction (core dumped)
There is no difference whey trying to compile the hello.swift program:
eugene@coconut:~$ which swift
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift
eugene@coconut:~$ swiftc hello.swift
error: compile command failed due to signal 4 (use -v to see invocation)
Please submit a bug report (Swift.org - Contributing) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend -frontend -c -primary-file hello.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -new-driver-path /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-driver -resource-dir /opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/lib/swift -module-name hello -o /tmp/TemporaryDirectory.WmQ1fQ/hello-1.o
Swift version 5.5.2 (swift-5.5.2-RELEASE)
While evaluating request ParseSourceFileRequest(source_file "hello.swift")
With parser at source location: hello.swift:1:22
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3efb3]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3ce9e]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5a3f335]
/lib/x86_64-linux-gnu/libc.so.6(+0x46520)[0x7f3a8468f520]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1d45c93]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1d424b9]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1949809]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac4503]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac051c]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abea43]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab911b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab8e0a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab861b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6c71]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6b18]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ac8c9a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ad8d2b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abd569]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1abd1a3]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab9812]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab9145]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab8e0a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab861b]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6c71]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ab6b18]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae22a0]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae41d4]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1a84f77]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae11d1]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x1ae1cdc]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19cfe84]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19cfb81]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19b823a]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x19b0bee]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x13d40dd]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x7121c1]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x712471]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x5601d0]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x4b140e]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dfd0)[0x7f3a84676fd0]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7d)[0x7f3a8467707d]
/opt/swift-5.5.2-RELEASE-ubuntu20.04/usr/bin/swift-frontend[0x4b104e]