All libraries by the system are in /lib and /use/lib.
As long as you compile stuff from source and place it in /use/local/lib , you shouldn’t be able to break any of the distro packages. You might need to take care during compiling packages that the versions in /use/local are preferred over the ones in /usr , but that often can be done with a simple pkgconfig rule .
Overwriting files from a distro package also should not result in the errors you describe. Apt may start complaining about it not wanting to overwrite files already there , but that can be forced.
The errors you describe come from dependency issues.
It sounds like you installed packages not meant or not compatible with your distro (or your distro version).
Specially if you ‘use a script from github’ it may very well just install stuff from a newer Ubuntu version into an old version or something like that.
Or from a rolling debian ibstallation where your installed versions are too far behind the rolling release .
There is never a clear cut simple answer in the Linux world , but I’d say stick with packages meant for your distro and distro version. Do not cross install debian stuff into Ubuntu or take a .Deb file from a newer Ubuntu version into an old.
If you want a newer version from a package / library, compile it from source and put it into /usr/local (which is 99% of the time the default from source installs) or somewhere in /opt . Places meant for stuff outside distro control . Then you’ll never ruin distro managed files and (more important) the dependency hell.
At some times I’d take a deb-SOURCE package from a newer Ubuntu version , and then use the dpkg tools to build a version that is compiled on my system.
But that still can overwrite files from the distro version and often requires some hacking in the build script to disable checks or disable features .
But I’d suggest compiling the libraries you want updated from source. But the real question is which libraries you want updating to the latest . For the whole GTK/glib stack i don’t see the point , stick to distro supplied stuff.
The same for libraries with little noticable features (libpng / zlib / libjpeg). I can understand it for things like avif and other newer , still in active development, dependencies.
But there should be no need to recompile everything. Often, just darktable itself with it’s git submodules is enough.