Search code examples
rcentosgisgdalrgdal

Having trouble installing rgdal and gdal on Centos


I had a hell of a time getting gdal installed today, even though I've been able to do it successfully in the past. I finally got it working, so if you're reading this I hope I can save you some time.

If you are running into issues like:

error while loading shared libraries: libgdal.so.20: cannot open shared object file: No such file or directory

or

ogr_sfcgal.h:34:34: fatal error: SFCGAL/capi/sfcgal_c.h: No such file or directory

or you're stuck on the yum rpm of gdal that's at 1.11, then I hope the answer below helps you.


Solution

  • First of all, make sure you have the dependencies installed, like SFCGAL:

    sudo yum install SFCGAL -y
    

    You might come across others with errors similar to the one above for SFCGAL. I'll leave it up to you to track them down and install them via yum.

    A recent RPM of gdal isn't available via yum, so you will have to install from source. What often happens with installing gdal, it seems to me, is that a user will install to /usr/local/bin rather than /usr/bin, which is where rgdal seems to look. This means you need to install to /usr/bin. But how can you do this without an RPM? You will install from source.

    It's simple. Download a >2.0 version of gdal here: https://trac.osgeo.org/gdal/wiki/DownloadSource

    And run the following:

    ./configure --prefix=/usr
    make
    sudo make install
    

    After this, you might get an error like

    error while loading shared libraries: libgdal.so.20: cannot open shared object file: No such file or directory
    

    You need to updated your shared library links. You can do this with:

    sudo ldconfig
    

    I hope this is helpful and that I saved you some time. I'm not an expert, so this might not be perfect advice. I wish you luck.