136

Please point out the point that I am missing:

openSUSE 11.3


xx@linux-y3pi:~/Desktop/R> sudo R CMD INSTALL rgdal_0.7-12.tar.gz 
root's password:
* installing to library ‘/usr/lib64/R/library’
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: gdal-config: gdal-config
checking gdal-config usability... ./configure: line 1353: gdal-config: command not found
no
Error: gdal-config not found
The gdal-config script distributed with GDAL could not be found.
If you have not installed the GDAL libraries, you can
download the source from  http://www.gdal.org/
If you have installed the GDAL libraries, then make sure that
gdal-config is in your path. Try typing gdal-config at a
shell prompt and see if it runs. If not, use:
 --configure-args='--with-gdal-config=/usr/local/bin/gdal-config'
with appropriate values for your installation.

ERROR: configuration failed for package ‘rgdal’
* removing ‘/usr/lib64/R/library/rgdal’

xx@linux-y3pi:~/Desktop/R> whereis gdal-config
gdal-config: /usr/local/bin/gdal-config

xx@linux-y3pi:~/Desktop/R> gdal-config 
Usage: gdal-config [OPTIONS]
Options:
 [--prefix[=DIR]]
 [--libs]
 [--dep-libs]
 [--cflags]
 [--datadir]
 [--version]
 [--ogr-enabled]
 [--formats]
 xx@linux-y3pi:~/Desktop/R>

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> 

xx@linux-y3pi:~/Desktop/R> gdal-config --version
1.9.0

xx@linux-y3pi:~/Desktop/R> proj
Rel. 4.8.0, 6 March 2012
usage: proj [ -beEfiIlormsStTvVwW [args] ] [ +opts[=arg] ] [ files ]

linux-y3pi:~ # $PATH
bash: /home/xx/qtsdk-2010.05/qt/bin/:/home/xx/qtsdk-2010.05/bin:/home/xx/qtsdk-2010.05/qt/bin:/home/xx/qtsdk-2010.05/qt/bin/:/home/xx/qtsdk-2010.05/bin:/usr/lib64/mpi/gcc/openmpi/bin:/home/xx/bin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games: No such file or directory
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • aha! `which gdal-config` returns `/usr/local/bin/gdal-config` but `sudo which gdal-config` returns `which: no gdal-config in (/sbin:/bin:/usr/sbin:/usr/bin)` – Brian D Jul 07 '20 at 22:37

10 Answers10

186

In Ubuntu 18.04

I fixed this by sudo apt install libgdal-dev Hope someone find this helpful. Some above answers seems to be outdated and lengthy.

In earlier versions (which had apt-get)

sudo apt-get install libgdal-dev

Gayan Kavirathne
  • 2,909
  • 2
  • 18
  • 26
105

You need the -dev package with headers and shared library links for development besides the normal package for deployment. Two different use cases as far as the distro is concerned.

On my distribution:

edd@max:/tmp$ dpkg -l | grep gdal | cut -c-72
ii  libgdal1-1.7.0                                1.7.3-6ubuntu3        
ii  libgdal1-dev                                  1.7.3-6ubuntu3        
edd@max:/tmp$ 

and R CMD INSTALL rgdal_0.7-8.tar.gz works just fine as you would expect from a CRAN package given all the build-time checks at CRAN.

Update late 2016: As @JoshO'Brien points out in the comment

Minor update: Here in 2016, running Ubuntu 14.04.2, libgdal1h seems to have replaced libgdal1(though libgdal1-dev is still needed). At least I get an error to that effect when I attempted to apt-get install libgdal1

For Ubuntu 16.04 the corresponding line would be
sudo apt-get install libgdal1i

Such renaming of upstream libraries is common; something such as apt-cache search libgdal can help locate the current package names. The important key though is that the "abstract" development package libgdal-dev is all that is needed to build as it pulls the "concrete" current run-time package (here: libgdal1i) in via a dependency.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 1
    Minor update: Here in 2016, running Ubuntu 14.04.2, `libgdal1h` seems to have replaced `libgdal1`(though `libgdal1-dev` is still needed). At least I get an error to that effect when I attempted to `apt-get install libgdal1`. – Josh O'Brien Jan 26 '16 at 20:21
  • 3
    +1 for putting me in the correct general direction. And since we are in 2018 and not everybody work on debian based systems,... on Arch linux the trick consists in doing `# pacman -Syu gdal` to download the rasterizing library from `community/gdal`. – Cbhihe May 07 '18 at 17:40
  • @BrianStamper Sure, but you realize the _answer is eight years old_ so what the (currently) correct set is can change over time. – Dirk Eddelbuettel Jul 27 '20 at 16:56
  • 2
    I hope you understand that 2012 was 8 years ago. I hope you are to read how the answer was already edited in 2016 for Ubuntu 16.04, and how in 2018 another answer was added. They key for you to understand here is the power of something like `apt-cache search libgdal` to _at any point in time_ find the _then-current_ name. That is fundamentally more valuable than a cookie cutter answer you copy without understanding. Because the cookies do get stale. – Dirk Eddelbuettel Jul 27 '20 at 20:32
38

You can use apt-file package, to find which package contains the missing file you are looking for.

First install the apt-file using the command apt-get install apt-file
Update apt-file using the command apt-file update
Now you can use apt-file to find the missing file. apt-file search gdal-config

For my case, I got the same error when configuring grass-7.1 from svn. As shown below:

    $ ./configure
    ...more...
    checking whether to use GDAL... yes
    checking for gdal-config... /usr/bin/gdal-config
                  ...more....
    ./configure: 1: ./configure: /usr/bin/gdal-config: not found
    ./configure: 6093: test: =: unexpected operator
    configure: error: *** Unable to locate GDAL library.

But, after looking for gdal-config file with apt-file as shown below, I was able to resolve the error, after installing the package libgdal1-dev

$ apt-file search gdal-config

Results

libgdal1-dev: /usr/bin/gdal-config

So I installed libgdal1-dev, as shown below:

$ sudo apt-get install libgdal1-dev
Erick
  • 1,408
  • 14
  • 19
  • 12
    This fixed the this error, but I also had to do `sudo apt-get install libproj-dev` to install `rgdal`. See http://stackoverflow.com/questions/15248815/rgdal-package-installation – geneorama Oct 28 '15 at 22:27
  • 3
    I can confirm that `libproj-dev` is also needed. R returns `configure: error: proj_api.h not found...` otherwise as mentioned by @geneorama. – narendra-choudhary Mar 28 '16 at 23:58
  • I confirm this, including the package in the comments, solved my problem for Ubuntu 16.04 and R 3.4. – luchonacho May 15 '17 at 08:53
  • In Ubuntu 19.10, R 3.6.2 I only had to `sudo apt-get install libgdal-dev`, no need for `libproj-dev`. Note: it was `libgdal-dev` not `libgdal1-dev`. – Rui Barradas Feb 05 '20 at 10:25
18

This happens because the configuration failed for package ‘rgdal’ so we have to install necessary dependencies.

The packages libgdal-dev and libproj-dev are required:

sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev

Then install rgdal by

install.packages("rgdal")

Load rgdal by

library(rgdal)
16

On macOS

brew install gdal

removed the error

gdal-config not found

lhaferkamp
  • 676
  • 8
  • 10
  • 1
    Just a tip for others, pay attention to the terminal output after running it, as there may be other things you need to do (I had to install something else before gdal would install, and I had to link it after installation - but brew let me know how to do this in the output) – stevec Apr 15 '20 at 13:07
  • I also had to brew install udunits geos proj then gdal – ski_squaw Sep 12 '21 at 17:46
  • 1
    `arch -arm64 brew install gdal` may help at Apple M1 chips. – zabala Jul 29 '22 at 22:31
5

Try this on CentOS 6

sudo yum install gdal gdal-python gdal-devel mapserver mapserver-python libxml2 libxml2-python python-lxml python-pip python-devel gcc
clemens
  • 16,716
  • 11
  • 50
  • 65
Wesam Na
  • 2,364
  • 26
  • 23
  • Unfortunately on my centos server sudo yum install gdal-devel fails with a long set of messages about processing dependencies and then a bunch of errors. They seem to involve centos 5 versions (eg gdal-1.8.0-4.el5.elgis.x86_64) but Im on centos 6. – JerryN Dec 20 '18 at 17:58
  • 5
    do we really need all of those? `sudo yum install gdal-devel` isn't enough? – Brian D Jun 12 '19 at 16:56
4

Read the reference manual.

SystemRequirements for building from source: GDAL >= 1.6.0 library from http://trac.osgeo.org/gdal/wiki/DownloadSource and PROJ.4 (proj >= 4.4.9) from http://trac.osgeo.org/proj/;

JJD
  • 50,076
  • 60
  • 203
  • 339
Roland
  • 127,288
  • 10
  • 191
  • 288
1

The same problem occurred today to me on a Linux CentOS 6.10 on which I do not have administration rights.

What I did:

a) Create a conda environment dedicated to my R version

conda create --name MYR

b) Activate the environment

source activate MYR

c) Install R

conda install -c conda-forge r-base

d) Install libgdal

conda install -c conda-forge libgdal

This solved the problem for me. My R version was 4.1.3. I guess other versions should work.

Fabio Marroni
  • 423
  • 8
  • 19
1

My Mac Monterrey continued to complain even after brew install gdal.

The suggestion in this github issue did the trick, though

install.packages("sf", type = "source", configure.args = 
'--with-gdal-lib=/opt/homebrew/opt/gdal/lib/ 
--with-sqlite3-lib=/opt/homebrew/opt/sqlite/lib/ 
--with-gdal-config=/opt/homebrew/bin/gdal-config
--with-proj-share=/opt/homebrew/opt/proj/share/ 
--with-proj-lib=/opt/homebrew/opt/proj/lib 
--with-proj-include=/opt/homebrew/opt/proj/include/
--with-geos-config=/opt/homebrew/opt/geos/bin/geos-config')
Him
  • 5,257
  • 3
  • 26
  • 83
0

For manjora or archlinux, just try: yay -S gdal

Yuchen BAI
  • 21
  • 2