Home Linux troubleshooting How To Fix “pacman: error while loading shared libraries” Error In Arch Linux

How To Fix “pacman: error while loading shared libraries” Error In Arch Linux

By sk
Published: Last Updated on 9.7K views

For the past few days, I have been extensively testing PIP and Pipenv tools in my Arch Linux system. While testing these tools, I had to reinstall and downgrade Python2.x, Python 3.x packages and some other Python dependencies package many times. At some point, It broke my Arch Linux and pacman stopped working. Whenever I run pacman, I got an error that says "pacman: error while loading shared libraries: libidn2.so.0: cannot open shared object file: No such file or directory".

pacman: error while loading shared libraries: libidn2.so.0: cannot open shared object file: No such file or directory

pacman: error while loading shared libraries: libidn2.so.0: cannot open shared object file: No such file or directory

Not just pacman, some other applications, such as pacaur, yaourt, packer, virtualbox and transmission etc., also stopped working. When I try to open any one of these applications, I keep getting this message - "error while loading shared libraries: libidn2.so.0: cannot open shared object file".

Chances are that I may have uninstall something that I couldn't remember. To my bad luck, It was my personal system and I don't want to reinstall it because it has a lot of applications. So, reinstalling OS and all applications might took two or may be more days.

After vigorously searching on Arch Linux wiki and other Linux forums like a mad man, I finally managed to fixed it. If you ever run into a problem something like this, look nowhere, just download the source file and copy the missing file(s) to /usr/lib/ folder. As far as I searched on the web, this method seems very easiest one so far. Read on to know how I fixed this error.

Fix "pacman: error while loading shared libraries" Error In Arch Linux

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
Update Arch Linux

Update Arch Linux

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:

You May Also Like

10 comments

Hannes Philipp January 22, 2018 - 9:11 pm

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 😀

Reply
SK January 23, 2018 - 11:31 am

I am so glad it helped you. BTW, What tool did you use to download “libidn2” package?

Reply
Gideon van der Merwe January 27, 2018 - 12:16 am

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.

Reply
Tayaout Labelle-Kuberek January 16, 2019 - 7:38 am

I did “sudo ln -s /usr/lib/libidn2.so /usr/lib/libidn2.so.0”!

Reply
Flo March 2, 2019 - 5:42 am

Haha, i did that too! Works also and even less to do.

Reply
Chris January 17, 2019 - 5:24 am

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.

Reply
racosa January 23, 2019 - 6:39 am

Thank you very much for posting this 🙂

Reply
Den January 25, 2019 - 10:24 pm

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! 🙂

Reply
Aaroncio January 28, 2019 - 7:08 pm

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

Reply
Mike March 12, 2019 - 7:40 pm

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.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More