For the past few days, I have been extensively testing PIP and Pipenv tools on my Arch Linux system. During this testing, I had to repeatedly reinstall and downgrade Python 2.x, Python 3.x, and several other Python dependency packages. At some point, this caused my Arch Linux installation to break, and pacman stopped working. Every time I ran pacman, I got the following error: "pacman: error while loading shared libraries: libidn2.so.0: cannot open shared object file: No such file or directory".

In addition to pacman, several other applications like pacaur, yaourt, packer, VirtualBox, and Transmission also stopped working. Whenever I tried to open any of these programs, I got the error: 'error while loading shared libraries: libidn2.so.0: cannot open shared object file.'
I suspect I may have accidentally uninstalled something, though I can't remember what. Unfortunately, this is my personal system, and I want to avoid reinstalling the OS because it has many applications. Reinstalling everything would take at least two days, if not more.
After frantically searching the Arch Linux wiki and other Linux forums, I finally managed to fix it. If you ever encounter a similar problem, don’t waste time searching - just download the source file and copy the missing file(s) to the `/usr/lib/` folder. From everything I found online, this method seems to be the easiest solution. Keep reading to learn how I fixed the error.
Fix "pacman: error while loading shared libraries" Error In Arch Linux
Method 1: Using pacman-static
As one of the commenter mentioned in the comment section, we can use "pacman-static" package from AUR. It is a pre-compiled binary. You can simply download it, make it executable, and reinstall the missing shared libraries.
Step 1: download the precompiled binaries from from this link.
curl -O https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/pacman-static
Step 2: Make it executable:
chmod +x pacman-static
Step 3: Reinstall pacman:
sudo ./pacman-static -S pacman
Step 4: Reinstall missing shared libraries:
sudo pacman -S libidn2 --force
Replace 'libidn2' with the missing library.
That's it.
If this method doesn't work for any reason, follow the 2nd method.
Method 2: The manual way
As I said already, I kept getting this error - "pacman: error while loading shared libraries: libidn2.so.0: cannot open shared object file: No such file or directory" when I run pacman command or any AUR helpers such as pacaur, packer, yaourt and I even can't open VirtualBox application and Transmission client. So, the actual problem here is the file "libidn2.so.0" has gone missing. We need to find it out!
$ ls -la /usr/lib/libidn*
Sample output from my Arch Linux system:
lrwxrwxrwx 1 root root 22 Jul 22 2013 /usr/lib/libidnkitlite.so -> libidnkitlite.so.1.0.2 lrwxrwxrwx 1 root root 22 Jul 22 2013 /usr/lib/libidnkitlite.so.1 -> libidnkitlite.so.1.0.2 -rw-r--r-- 1 root root 276352 Jul 22 2013 /usr/lib/libidnkitlite.so.1.0.2 lrwxrwxrwx 1 root root 18 Jul 22 2013 /usr/lib/libidnkit.so -> libidnkit.so.1.0.2 lrwxrwxrwx 1 root root 18 Jul 22 2013 /usr/lib/libidnkit.so.1 -> libidnkit.so.1.0.2 -rw-r--r-- 1 root root 282368 Jul 22 2013 /usr/lib/libidnkit.so.1.0.2 lrwxrwxrwx 1 root root 17 Aug 15 19:00 /usr/lib/libidn.so -> libidn.so.11.6.16 lrwxrwxrwx 1 root root 17 Aug 15 19:00 /usr/lib/libidn.so.11 -> libidn.so.11.6.16 -rwxr-xr-x 1 root root 210872 Aug 15 19:00 /usr/lib/libidn.so.11.6.16
I had "libidn.so", but can't find "libidn2.so.0". Since pacman and any other package manager didn't work, there is no way to install, upgrade or downgrade any packages from official repository or local cache. So, I thought that the only way might be to download the package that has the missing file from Internet, extract it and finally copy the missing file(s) to /usr/lib/ directory. Let me create a directory to save libdin2 tar file:
$ mkdir libidn
$ cd libidn
Find and download the latest version of this package. A quick google search brought me here. Extract the file:
$ tar xf libidn2-2.0.4-2-x86_64.pkg.tar.xz
The above command extracted the contents of the file in a directory named "usr". Go to the usr/lib folder: (Note - It is usr/lib, not /usr/lib)
$ cd usr/lib
Finally copy the missing file, in our case it is libidn2.so.0, to /usr/lib/ directory of your Arch Linux system.
$ sudo cp libidn2.so.0 /usr/lib/
Then, I ran:
$ sudo pacman -syu

Voila! Pacman works now!! Oops! Oh no, wait.. It didn't work. I got this error after few minutes.
[....] (511/511) checking keys in keyring [######################] 100% (511/511) checking package integrity [######################] 100% (511/511) loading package files [######################] 100% (511/511) checking for file conflicts [######################] 100% error: failed to commit transaction (conflicting files) libidn2: /usr/lib/libidn2.so.0 exists in filesystem Errors occurred, no packages were upgraded.
To fix this, I ran:
$ sudo pacman -S libidn2 --force
Then, I tried update again:
$ sudo pacman -Syu
Fixed!! All good now. So, if you guys ever run into an issue something like "error while loading shared libraries: .. cannot open shared object file: No such file or directory", one way to fix this is to find the the package that contains the missing files, download the latest version of that package, extract it and copy the missing files to /usr/lib/ directory.
Of course, there could be many ways to fix such kind of issues. But this is the only working solution I could find and I find this much easier and faster. This trick might work on other Linux distros too.
Related read:
- How To Fix Broken Pacman In Arch Linux
- How To Restore Broken Arch Linux To Previous Working State
- How To Fix “unable to lock database” Error In Arch Linux
- How To Fix “invalid or corrupted package (PGP signature)” Error In Arch Linux
- How To Solve “Starting full system upgrade… there is nothing to do” Issue In Arch Linux
- How To Solve “error: failed to commit transaction (conflicting files)” In Arch Linux

10 comments
Thank you very much! That saved me a lot of time… 🙂 After not having upgraded for 3 months, ignoring unresolvable package version conflicts rendered me libidn2-less. Now everything works fine again. Remark: on my computer, even wget needs libidn2… so that line did unfortunately not work for me 😀
I am so glad it helped you. BTW, What tool did you use to download “libidn2” package?
Thanks ! I had a similar issue once before and had to chroot with a live arch disc a few times to solve it. Glad I cam upon this post, but reading through your post, it makes a lot of sense.
I did “sudo ln -s /usr/lib/libidn2.so /usr/lib/libidn2.so.0”!
Haha, i did that too! Works also and even less to do.
By the way, for anyone who breaks pacman, fixing it manually is pretty tedious, you can also use pacman-static (available on the AUR, with precompiled downloads) to fix your broken install. It has no library dependencies whatsoever and so will work whatever the state of libraries on your system is.
Thank you very much for posting this 🙂
I had the file located where it should be but still there was that error. So I re-downloaded the package and copied it to the dir. Then everything works again! 🙂
Thanks. you saved me.
The link is broken, but I found the packages here https://fraggod.net/static/mirror/packages/archlinux/x86_64/
downloading libidn2-2.0.5-1-x86_64.pkg.tar.xz for libidn2.so.0 and libidn2-2.1.0-1-x86_64.pkg.tar.xz for libidn2.so.4
This was much easier to fix for me.
ls -la /usr/lib/libidn2*
lrwxrwxrwx 1 root root 16 Feb 10 21:11 /usr/lib/libidn2.so -> libidn2.so.0.3.5
lrwxrwxrwx 1 root root 16 Feb 10 21:11 /usr/lib/libidn2.so.0 -> libidn2.so.0.3.5
-rwxr-xr-x 1 root root 120512 Feb 10 21:11 /usr/lib/libidn2.so.0.3.5
cd /usr/lib
sudo ln -s libidn2.so libidn2.so.4
And then pacman/yay worked.