I am aware there are a few similar questions to this one, such as here and here. My problem is however a bit different.

I've recently upgraded my Ubuntu to 20.04 and there only PostgreSQL 12.3 and PostGIS 3.0 are fetchable on the official repo. This means that getting earlier versions is not very straightforward.

Thinking that the easiest way forward would be to also upgrade my Django database to the latest version above, I decided to try that. To my surprise, I keep getting the following error:

could not access file "$libdir/postgis-2.4": No such file or directory

This happened first in my Django app but naturally also when accessing the database via psql directly. I then proceeded to drop the database and create it again, as luckily the data I had there was still only test stuff. As soon as I try to create the PostGIS extension to it, guess which error I get...

mydb=# CREATE EXTENSION postgis;
ERROR:  could not access file "$libdir/postgis-2.4": No such file or directory

My conclusion is that it doesn't seem to be a problem directly related to the upgrade of postgis to 3.0, as I'm not even able to create the extension. Also, I don't understand why it tries to access the 2.4 version as it is a brand new database. Restarting the PostgreSQ service or even the computer wasn't of any help.

How can I approach this problem?

  • have you seen this post?
    – JGH
    Commented Jun 12, 2020 at 19:25
  • I hadn't. Unfortunately it doesn't help in my case. postgresql-12-postgis-2.5 is not reference in my apt, only postgresql-12-postgis-3, which is already installed: postgresql-12-postgis-3 is already the newest version (3.0.0+dfsg-6ubuntu4).
    – edwillys
    Commented Jun 12, 2020 at 19:36

3 Answers 3


Possibly unrelated, but when I ran into the same error message, I was able to fix it by running ALTER EXTENSION postgis UPDATE;

  • I would suggest that anyone who has this issue try this first. It takes a few seconds to login and try it. Worked for me on my Gentoo Linux install. Much simpler than removing and reinstalling packages.
    – SimonAlfie
    Commented Jun 21, 2021 at 15:21
  • Unfortunately when I did this it generated more-or-less the same error: could not access file "$libdir/postgis-3": No such file or directory.
    – cazort
    Commented Sep 15, 2023 at 2:04

I ended up fixing the issue. The problem seems to be due to the fact that there were still many 'residual' folders from older versions of postgresql still present on


even after removing them with apt remove. The result is that after reinstalling postgresql and postgresql-common, the binary psql was linked to and older version of it, which itself was linked to an older version of postgis (in my case 2.4), that was not present anymore. I'm still not sure whether this was a problem with the upgrade on Ubuntu or the upgrade of postgresql.

The solution is basically really remove all of postgresql, postgis and postgresql-common packages before re-installing them with apt install. I took the hard path of manually removing the folders myself, which in turn led to an incredible mess of packaging managers not being able to install, clean or remove them anymore, as they were broke. I definitely do not recommend this approach. Instead, it should be possible to properly force the removal of packages:

  1. Find all of the relevant postgresql and postgis packages that are installed:
    dpkg -l | grep postgis
    dpkg -l | grep postgresql
  1. Force delete them with
    sudo dpkg --remove --force-all <package_name>
  1. Reinstall them with apt install
  • By the way, if you end up manually deleting those folders, here are some threads that helped me cleaning up things: askubuntu.com/questions/141370/… askubuntu.com/questions/940419/…
    – edwillys
    Commented Jun 13, 2020 at 10:52
  • Thanks for this. In my case, after running dpkg -l | grep postgis I immediately noticed that postgis wasn't even installed. I must've accidentally removed it a couple of days earlier.
    – narrowtux
    Commented Mar 12, 2021 at 12:26

On my side the solution was to re-install the version of postgis :

sudo apt install postgis postgresql-11-postgis-2.5

Be Carefull with the pg version,

Hope it will be usefull

  • How are you getting this command to work? When I use postgresql-11-postgis-2.5 it just says: Package postgresql-11-postgis-2.5 is not available, but is referred to by another package.
    – cazort
    Commented Sep 15, 2023 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.