Skip to content

Instantly share code, notes, and snippets.

@dncgst
Last active February 8, 2024 13:45
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dncgst/111b74066eaea87c92cdc5211949cd1e to your computer and use it in GitHub Desktop.
Save dncgst/111b74066eaea87c92cdc5211949cd1e to your computer and use it in GitHub Desktop.
How to install the rgdal R package

How to install the rgdal R package

> install.packages("rgdal")

  • installing source package ‘rgdal’ ... configure: error: gdal-config not found or not executable.

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

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

@brianpenghe
Copy link

Thanks!

@elgabo82
Copy link

On RedHat based systems like Fedora:
sudo dnf install gdal* expat* proj*

Then install.packages("rgdal")

This worked for me.

@Andrew-Kao
Copy link

Just bumping this in case @statgeek or anyone else managed to solve the problem when there's no sudo access?

@statgeek
Copy link

We upgraded our Unix version and that fixed it on our side but I had to wait 6 months for it.

@cffiorini
Copy link

cffiorini commented Dec 17, 2019

Hi, I am using Ubuntu 18.04, R 3.4.4 (2018-03-15), and Rstudio 1.2.1335.

I ran sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev and got the following output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
gdal-bin is already the newest version (2.2.3+dfsg-2).
gdal-bin set to manually installed.
libgdal-dev is already the newest version (2.2.3+dfsg-2).
libproj-dev is already the newest version (4.9.3-2).
proj-bin is already the newest version (4.9.3-2).
proj-bin set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.

After running install.packages("rgdal") I keep seen the following:
Installing package into ‘/home/fiorini/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available (for R version 3.4.4)

Could you please help me?

Thanks!

@prajwal-stha
Copy link

Works for me !!

Thanks!!

@elgabo82
Copy link

elgabo82 commented Jan 6, 2020

Hi, I am using Ubuntu 18.04, R 3.4.4 (2018-03-15), and Rstudio 1.2.1335.

I ran sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev and got the following output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
gdal-bin is already the newest version (2.2.3+dfsg-2).
gdal-bin set to manually installed.
libgdal-dev is already the newest version (2.2.3+dfsg-2).
libproj-dev is already the newest version (4.9.3-2).
proj-bin is already the newest version (4.9.3-2).
proj-bin set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.

After running install.packages("rgdal") I keep seen the following:
Installing package into ‘/home/fiorini/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available (for R version 3.4.4)

Could you please help me?

Thanks!

Maybe this link could be useful!!!

https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/

@cffiorini
Copy link

Hi, I am using Ubuntu 18.04, R 3.4.4 (2018-03-15), and Rstudio 1.2.1335.
I ran sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev and got the following output:
Reading package lists... Done
Building dependency tree
Reading state information... Done
gdal-bin is already the newest version (2.2.3+dfsg-2).
gdal-bin set to manually installed.
libgdal-dev is already the newest version (2.2.3+dfsg-2).
libproj-dev is already the newest version (4.9.3-2).
proj-bin is already the newest version (4.9.3-2).
proj-bin set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.
After running install.packages("rgdal") I keep seen the following:
Installing package into ‘/home/fiorini/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available (for R version 3.4.4)
Could you please help me?
Thanks!

Maybe this link could be useful!!!

https://philmikejones.me/tutorials/2014-07-14-installing-rgdal-in-r-on-linux/

Hi! Thank you!!!

Updating R to 3.6.2 solved the issue.

Best,

Cecilia

@romunov
Copy link

romunov commented Apr 5, 2020

sudo dnf install gdal* expat* proj*

worked for me on Fedora 31.

@Akronix
Copy link

Akronix commented Apr 17, 2020

For other old-fashioned users, as me, still on Ubuntu 16.04, first I needed to install R 3.6 from cran35 repo: I recommend you to follow the instructions described in the second answer to this question in stackoverflow.
And then I had to add and use the ubuntu-gis ppa: https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa to install the packages described above, because the version of gdal-bin in the official repo is not recent enough.

@irenelfeng
Copy link

| sudo dnf install gdal* expat* proj*

noting that I still needed to download sqlite3-devel (sudo dnf install libsqlite3x-devel) on CentOS8, if anyone else encounters issues.

@jose-ramirez
Copy link

sudo dnf install gdal* expat* proj*

Even though it works, I found out that this command ends up installing too many dependencies, especially when (in my case) I only needed two packages to be able to compile the library's native code: sudo dnf install -y gdalcpp-devel proj-devel was the bare minimum I needed to install the library at the time.

@RiccardoForconi
Copy link

RiccardoForconi commented Aug 5, 2020

Installing the package it gives me this error:

projectit.cpp:159:95: error: expected ‘,’ or ‘...’ before ‘SEXP’
 P toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z SEXP aoi) {
                                                           ^~~~
projectit.cpp: In function ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’:
projectit.cpp:159:6: error: conflicting declaration of C function ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’
 SEXP transform_ng(SEXP fromargs, SEXP toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z SEXP aoi) {
      ^~~~~~~~~~~~
In file included from projectit.cpp:11:0:
rgdal.h:132:6: note: previous declaration ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’
 SEXP transform_ng(SEXP fromargs, SEXP toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z, SEXP aoi); // both
      ^~~~~~~~~~~~
/usr/lib/R/etc/Makeconf:176: recipe for target 'projectit.o' failed
make: *** [projectit.o] Error 1
ERROR: compilation failed for package ‘rgdal’
* removing ‘/usr/local/lib/R/site-library/rgdal

Anyone knows how to fix this?

@maxbre
Copy link

maxbre commented Aug 6, 2020

same error here

/usr/lib/R/etc/Makeconf:177: recipe for target 'projectit.o' failed
make: *** [projectit.o] Error 1
ERROR: compilation failed for package ‘rgdal’

on this system:

debian 9 stretch
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

any help for that?

@cstangens
Copy link

cstangens commented Aug 6, 2020

Installing the package it gives me this error:

projectit.cpp:159:95: error: expected ‘,’ or ‘...’ before ‘SEXP’
 P toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z SEXP aoi) {
                                                           ^~~~
projectit.cpp: In function ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’:
projectit.cpp:159:6: error: conflicting declaration of C function ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’
 SEXP transform_ng(SEXP fromargs, SEXP toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z SEXP aoi) {
      ^~~~~~~~~~~~
In file included from projectit.cpp:11:0:
rgdal.h:132:6: note: previous declaration ‘SEXPREC* transform_ng(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)’
 SEXP transform_ng(SEXP fromargs, SEXP toargs, SEXP coordOp, SEXP npts, SEXP x, SEXP y, SEXP z, SEXP aoi); // both
      ^~~~~~~~~~~~
/usr/lib/R/etc/Makeconf:176: recipe for target 'projectit.o' failed
make: *** [projectit.o] Error 1
ERROR: compilation failed for package ‘rgdal’
* removing ‘/usr/local/lib/R/site-library/rgdal

Anyone knows how to fix this?

I installed rdgal from github with devtools:
devtools::install_github("CRAN/rgdal")

Somehow github rgdal compiles fine.

@maxbre
Copy link

maxbre commented Aug 6, 2020

this worked for me (a workaround until the next new release for all platforms)

install.packages("rgdal", repos="http://R-Forge.R-project.org")

@Murilodsv
Copy link

I've been trying to install in a server without having writing permissions. So far, I could get it installed through $ conda install -c conda-forge r-rgdal. But I keep getting this weird warning every time I try to read a raster.tif:

Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
  Discarded datum Unknown based on GRS80 ellipsoid in CRS definition

When installing in my local ubuntu, the sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev works beautifully with no warnings while opening the same rasters.

@rvpanaro
Copy link

rvpanaro commented Nov 3, 2020

sudo apt-get install gdal-bin proj-bin libgdal-dev libproj-dev has worked for me, thanks.
Ubuntu 20.04 R version 4.0.3 (2020-10-10)

@allswellthatsmaxwell
Copy link

Thank you!! This helped me.

@mskyttner
Copy link

Ended up here when installing dependencies for using "rgdal", "sp" and "raster" on up-to-date Linux on 20.04 package base without spatial libs installed on the system.

For me, libmysqlclient-dev default-libmysqlclient-dev gdal-bin proj-bin libgdal-dev libproj-dev were system libraries required on freshly installed Linux Mint 20.04 with R v 4.0.3 when installing from source R packages raster v 3.4-5 (2020-11-14), rgdal v 1.5-18 (2020-10-13) and sp v 1.4-4 (2020-10-07) from CRAN.

This OS setup doesn't seem to need or require use of ubuntugis PPA, which anyways doesn't have 20.04 focal packages. On https://rgdal.r-forge.r-project.org/index.html some docs mention that "it is important that 'GDAL' < 3 be matched with 'PROJ' < 6. From 'rgdal' 1.5-8, installed with to 'GDAL' >=3, 'PROJ' >=6 and 'sp' >= 1.4, coordinate reference systems use 'WKT2_2019' strings, not 'PROJ' strings. 'Windows' and 'macOS' binaries (including 'GDAL', 'PROJ' and their dependencies) are provided on 'CRAN'. "

The system libraries versions seem to play with that combination:

$ apt-cache policy libgdal-dev libproj-dev
libgdal-dev:
  Installed: 3.0.4+dfsg-1build3
libproj-dev:
  Installed: 6.3.1-1

R codes now show some new warnings, possibly due to now need to use "'WKT2_2019' strings, not 'PROJ' strings". Examples of how such warnings can look:

1: In wkt(projfrom) : CRS object has no comment
2: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
3: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded datum World Geodetic System 1984 in CRS definition
4: In wkt(pfrom) : CRS object has no comment
5: In rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[,  :
  Using PROJ not WKT2 strings
6: In wkt(pfrom) : CRS object has no comment
7: In rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[,  :
  Using PROJ not WKT2 strings
8: In rgdal::rawTransform(projto_int, projfrom, nrow(xy), xy[, 1],  :
  Using PROJ not WKT2 strings
9: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
10: In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded datum World Geodetic System 1984 in CRS definition

I think one has to migrate old code that is using PROJ strings to use 'WKT2_2019' strings instead to get rid of the warnings while non-migrated code still seems to work (?).

@MiriamRoh
Copy link

hello,
I am new to ubuntu and my version is popOs 19.10.
and I am also new to github.

Sadly I get this erreor after trying to install rdgal in RStudio:

configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘rgdal’

  • removing ‘/home/me/R/x86_64-pc-linux-gnu-library/3.6/rgdal’
    Warning in install.packages :
    installation of package ‘rgdal’ had non-zero exit status

and the sudo commant presented before doesn't work for me.
has anyone more wisdom and knowledge and can help me please

thank you

@mskyttner
Copy link

If you have docker you could try to leapfrog installing the system libraries altogether with this oneliner docker run -d --name geospatial -p 8787:8787 -v /home/me:/home/rstudio -e PASSWORD=rocker rocker/geospatial:3.6.3 && sleep 5 && firefox http://localhost:8787 which gets everything needed in an isolated environment which includes all dependencies needed.

If the command you used didn't work, and you don't want to "cheat" by using a container, the error messages you have might lead you in the right direction (try searching on the error message at SO or in another search engine). When I do dpkg -l | grep gdal I have libgdal-dev listed, which I believe gave gdal-config (I'm not on popOS but on an earlier Ubuntu base). The command apt-file search gdal-config seems to agree that it should come in libgdal-dev (but I'm on Ubuntu 18 base).

@andrego50
Copy link

Thanks! It worked for me

@hrlai
Copy link

hrlai commented Jun 15, 2021

Just bumping this in case @statgeek or anyone else managed to solve the problem when there's no sudo access?

Try this SO page https://askubuntu.com/questions/193695/installing-packages-into-local-directory it helped me.

@tomasiojanuario
Copy link

Many thanks. It worked
Muito obrigado pela dica

@YohansB
Copy link

YohansB commented Sep 1, 2021

Many thanks, that fixed it!

@DrDids
Copy link

DrDids commented Jan 4, 2022

Hi, I used

> install.packages("rgdal", repos="https://cloud.r-project.org/")

worked like a charm

Didier

P.S.
the normal install gave (I had also tried another CRAN repo):

in download.file(url, destfile, method, mode = "wb", ...) :
download from 'https://pbil.univ-lyon1.fr/CRAN/bin/macosx/contrib/4.1/rgdal_1.5-28.tgz' failed
In addition: Warning messages:
1: In download.file(url, destfile, method, mode = "wb", ...) :
downloaded length 19824640 != reported length 91041577
2: In download.file(url, destfile, method, mode = "wb", ...) :
URL 'https://pbil.univ-lyon1.fr/CRAN/bin/macosx/contrib/4.1/rgdal_1.5-28.tgz': Timeout of 60 seconds was reached
Warning in download.packages(pkgs, destdir = tmpd, available = available, :
download of package ‘rgdal’ failed

@lucas-oliaro
Copy link

Thanks :)

@hyousefi89
Copy link

Hello
I couldn't install RGDAL. Please help.

install.packages("rgdal", type = "source")
Installing package into ‘C:/Users/Hossein/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

@tomasiojanuario
Copy link

tomasiojanuario commented Feb 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment