Nix-channel: error while loading shared libraries: libxml2.so.16: cannot open shared object file

This seemed to happen out of nowhere, but I simply ran:

[nprevail@nixos:~]$ sudo nixos-rebuild switch --upgrade

and then the output was this:

unpacking 2 channels... 
nix-channel: error while loading shared libraries: libxml2.so.16: cannot open s
hared object file: No such file or directory 
nix-instantiate: error while loading shared libraries: libxml2.so.16: cannot op
en shared object file: No such file or directory 
building the system configuration... 
nix-build: error while loading shared libraries: libxml2.so.16: cannot open sha
red object file: No such file or directory 
Command 'nix-build '<nixpkgs/nixos>' --attr config.system.build.toplevel --no-o
ut-link' returned non-zero exit status 127.
 ```

My channels are the following:

[nprevail@nixos:~]$ sudo nix-channel --list 
[sudo] password for nprevail: 
nixos https://nixos.org/channels/nixos-25.11
unstable https://nixos.org/channels/nixos-unstable

Any ideas?

unset LD_LIBRARY_PATH, then try again.

If that works, figure out why that is set at all, and remove the setting for that.

1 Like

Nearly a week has passed, have you been able to solve your problem, or does it still persist?

Sorry for the late response.

After running unset LD_LIBRARY_PATH in konsole/terminal, I think I got the same result… After running that command, there was no output, but the command did go through. Was I to run it with sudo? Because I did the second time around.

Afterwards, I ran sudo nixos-rebuild switch --repair, and I was able to run sudo nixos-rebuild switch --upgrade

So in the end, I’m not sure which command did the trick, but it’s working for me now.