Ubuntu 25.10 and libxml2

Just posting for notice. On Ubuntu 25.10 arm64 when doing something like

swift package init --name MyLibrary --type library

using 6.2.0 I’m getting the error

error while loading shared libraries: libxml2.so.2: cannot open shared object file: No such file or directory

After going down a rabbit hole I think I’m running into this issue:

which doesn’t seem like there’s much to do. I just wanted to raise awareness.

Right, there are a couple of things going on. Most importantly, Swift currently does not provide pre-built binaries for Ubuntu 25.10. I believe the pre-built binaries are always available for all supported LTS versions -- the latest to date is Ubuntu 24.04 (see Install Swift | Swift.org , currently binaries for 20.04, 22.04 and 24.04 are provided).

So I'll assume that you installed the Swift binaries for Ubuntu 24.04 and are attempting to run them on Ubuntu 25.10. This isn't usually gonna work and let's see exactly what's going on:

root@c9c40418cd59:/# /root/.local/share/swiftly/toolchains/6.2.1/usr/bin/swift package init
/root/.local/share/swiftly/toolchains/6.2.1/usr/bin/swift-package: error while loading shared libraries: libxml2.so.2: cannot open shared object file: No such file or directory

So it says it wants libxml2.so.2 but Ubuntu 25.10 provides

root@c9c40418cd59:/# ls /usr/lib/aarch64-linux-gnu/libxml2.so*  
/usr/lib/aarch64-linux-gnu/libxml2.so.16  /usr/lib/aarch64-linux-gnu/libxml2.so.16.0.5

and unfortunately, the libxml2.so.16 is the only package provided by Ubuntu:

root@c9c40418cd59:/# apt-cache search ^libxml2
libxml2-16 - GNOME XML library  <<<--- see the ...-16
libxml2-dev - GNOME XML library - development files
libxml2-doc - GNOME XML library - documentation
libxml2-utils - GNOME XML library - utilities

tl;dr Yes, your analysis was correct, this new Ubuntu only provides an ABI-breaking libxml2 which isn't compatible with any of the pre-built Swift toolchains available today. But to be honest, even if you solve the libxml2 issue by installing (maybe through a PPA or some other way), there's no guarantee that there won't be yet another issue like this. Linux distributions generally only guarantee ABI stability within a release, not across them. Or in other words: A Swift toolchain for Ubuntu 24.04 isn't expected to work on Ubuntu 25.10.

1 Like

So I'll assume that you installed the Swift binaries for Ubuntu 24.04 and are attempting to run them on Ubuntu 25.10.

Yep that’s correct. I had a virtual machine that I upgraded from 24.04 to 25.10 earlier this week and ran into this issue. No big deal in my case, I can go back to a previous snapshot. I just wanted to make others aware. I appreciate the expansion on the topic.

1 Like

I was able to install a libxml2 package from the previous version of Ubuntu (25.04) on my 25.10 install and that resolved the libxml2.so.2 error for me. The package is here:

https://launchpad.net/ubuntu/+archive/primary/+files/libxml2_2.12.7+dfsg+really2.9.14-0.4ubuntu0.4_amd64.deb

Just to let you know this is a possible workaround.

A possible (and temporary) workaround is to simply create a symbolic link to libxml2.so.16

sudo ln -s /lib/x86_64-linux-gnu/libxml2.so.16 /lib/x86_64-linux-gnu/libxml2.so.2

Consequently swiftly compiles as expected but emits warnings.
To avoid these warnings, the riskier approach is indeed to add libxml2.so.2.9.14 (compatible with ubuntu 24.04) and then create a symbolic link.

wget https://launchpad.net/ubuntu/+archive/primary/+files/libxml2_2.12.7+dfsg+really2.9.14-0.4ubuntu0.4_amd64.deb
sudo dpkg --fsys-tarfile libxml2_2.12.7+dfsg+really2.9.14-0.4ubuntu0.4_amd64.deb | tar -xO ./usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14 > /lib/x86_64-linux-gnu/libxml2.so.2.9.14
sudo ln -s /lib/x86_64-linux-gnu/libxml2.so.2.9.14 /lib/x86_64-linux-gnu/libxml2.so.2

Ubuntu 26.04’s development release (that will become LTS) is also affected by the same problem.
The issue is that the older implementation of libxml2 has significant drawbacks (libxml2 narrowly avoids becoming unmaintained)

1 Like