Pages Menu
Categories Menu

Posted by on Nov 2, 2010 in R Spatial, Resources | 16 comments

Installing rgdal on Mac OS X

******Roger Bivand has kindly just emailed me to say:

“Your 2 November blog about rgdal on OSX is very misleading. The CRAN rgdal page: says all you need to know unless you need extra drivers, or already have PROJ.4 and GDAL installed. Just do:


installs rgdal with all its external dependencies satisfied. It is kindly provided by Prof. Brian Ripley, and is presently running up-to-date GDAL.”******

This may offer a straightforward solution. I would be interested to hear how people get on.

After running a spatial data analysis with R session today, it became apparent that there are one or two teething problems installing the important rgdal package on Mac OS X operating systems. The usual install.packages(“rgdal”) won’t work. My colleague Jon Reades did some digging around to find this solution. I have tested it and it seems to work fine.

[Note that you’ll need to be comfortable with the Terminal. If you’re not, then find someone who is.]

1. Download the GDAL OS X install from kyngchaos
(Looks like the basic page [for updates after 1.7 if you’re reading this ages from now] is
– Install as per usual OS X install system
– Fire up the Terminal, then pico (or vi[m]) the .bash_login file
– Modify the PATH environment so that it reads:
export PATH=”/Library/Frameworks/GDAL.framework/Programs:$PATH”
[This is what enables the subsequent steps to find gdal-config]

2. Download and install proj4 from source
– Download source code version proj-4.7.0.tar.gz
– Fire up the Terminal
> cd ~/Downloads/
> tar -xzvf proj-4.7.0.tar.gz
> cd proj-4.7.0
> ./configure
> make && make test
> sudo make install
[ should install to /usr/local/lib by default]

3. Download and install rgdal from source
– Fire up the Terminal
> cd ~/Downloads/
> sudo R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_0.6-28.tar.gz

After all of this mucking about I was able to say:

> require(sp)
> require(rgdal)

And get a message indicating that GDAL was loaded successfully.

He also posted his solution on the Computational Mathematics Blog. If there is a better way I would be interested in hearing about it for future classes.


  1. If you have homebrew ( installed in /usr/local, then it is as easy as:

    brew install gdal
    R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_0.6-28.tar.gz

    thats it.

    then in R I get:

    > require(rgdal)
    Loading required package: rgdal
    Loading required package: sp
    Geospatial Data Abstraction Library extensions to R successfully loaded
    Loaded GDAL runtime: GDAL 1.7.2, released 2010/04/23
    Path to GDAL shared files: /usr/local/Cellar/gdal/1.7.2/share/gdal
    Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009
    Path to PROJ.4 shared files: (autodetected)

  2. If you have the kyngchaos PROJ4 framework ( already installed, there is no need to install proj4 from source again. This worked for me on 10.5.8:

    R CMD INSTALL -l /Users/PUT_USERNAME_HERE/Library/R/2.12/library –configure-args=’–with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config –with-proj-include=/Library/Frameworks/PROJ.framework/Versions/Current/Headers –with-proj-lib=/Library/Frameworks/PROJ.framework/Versions/Current/unix/lib’

    (This also installs rgdal on the user level, as recommended.)

  3. thanks for the post. got me up and running.

    note of caution, though. when i edited the .bash_login file i altered the default $PATH location in the, so i lost access to pico vi etc… and couldn’t restore the bash default path. ended up having to track it down using text wrangler (it’s a hidden file, so made it that much more interesting)

    thread at provides code so you don’t have to alter your path file:

    > –configure-args=”–with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config
    > –with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib
    > –with-proj-include=/Library/Frameworks/PROJ.framework/unix/include”
    > rgdal_0.6-20.tar.gz

  4. Good comments and good insights I see — I have to install gdal and proj4 on another OSX machine later this week and will be trying out the other approaches that people are suggesting. Mine was cobbled together from Google searches and trial-and-error in a (for me) new environment, so I’m not surprised that there’s a better way to do it…

    A couple of comments/observations:

    1. I only found out that KyngChaos had also produced a Proj4 installer *after* I’d finished installing Proj4 from source, so that’s why the instructions were a little… detailed. I definitely think that if that second installer works then I’d have used that as my first choice; however, in chatting with James it seemed like it would make sense for me to share the version that I knew for a fact worked rather than the version that *should* logically work. 🙂

    2. Sorry about the issues with the Path charlie — I was trying to keep it simple (i.e. adding “:$PATH” should have ensured the rest of your Path environment was left alone) by focussing on what you needed to add, but it’s a bit temperamental that way and I’m glad to hear you got it sorted. Looks like all command line parameters would be a better solution.


  5. to “Cameron Bracken”:
    It worked for me… I had been STRUGGLING for days to get this package into R and I can’t believe it just took too lines.

    For those struggling:

    1- download rgdal_0.6-29.tgz and put in your download folder.
    2- open the terminal
    3- go to “Shell>New Window>Homebrew” (a dark window opens)
    4- cd Dowloads to get into your dowloads folder
    5- copy paste the following:

    R CMD INSTALL –configure-args=’–with-proj-include=/usr/local/lib’ rgdal_0.6-29.tar.gz

    you’ll get this:
    * installing to library ‘/Library/Frameworks/R.framework/Resources/library’
    * installing *binary* package ‘rgdal’ …
    * DONE (rgdal)

    6- go to R and type require(rgdal), that’s it.

    I have no clue what Homebrew really does or how it differs from the normal terminal window. If you’re clueless like me, this worked! good luck!

  6. you can use the install.packages() from within R using the configure.args for specifying the locations of gdal-config etc.

    Unfortunately I’m getting this now:

    > require(rgdal)
    Loading required package: rgdal
    Failed with error: ‘package ‘rgdal’ is not installed for ‘arch=x86_64”

  7. I’ve tried many different options, but I keep getting this message:

    Error in getOct(block, 100, 8) : invalid octal digit

    Any hints?

  8. Here’s what worked on OS X 10.6.7 (Snow Leopard, i386 architecture, R version 2.12.2):

    1) Download the “GDAL Complete” framework from and install.

    2) Open R, and on the startup panel in preferences, make sure the “Add ~/Library/R…” is checked (enables user-level install).

    3) Use the R package installer (in Packages & Data menu) to install the sp package. CRAN binaries can be used, but select “at user level” for install location.

    4) Download the rgdal package source from CRAN to a local drive.

    5) Open Terminal, cd to the directory containing the rgdal source *.tar.gz file (e.g. rgdal_0.6-33.tar.gz), and install with the following command: R CMD INSTALL —configure-args=’—with-gdal-config=/Library/Frameworks/GDAL.framework/unix/bin/gdal-config —with-proj-include=/Library/Frameworks/PROJ.framework/unix/include —with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib’ rgdal_0.6-33.tar.gz

    One thing to note is that the must be used even on an i386 architecture.

  9. This has driven me crazy for a while. As it turns out though, there seems to be an easy solution:

    setRepositories(ind=1:2) # adds Cran extras repo
    install.packages(“rgdal”) #now it works!

    • Tom,
      Your solution implies having installed GDAL
      from the kyngchaos site previously, right?
      Also, did anybody else find any problem with this
      procedure that is considerably less complicated than the rest of those mentioned in this page?


  10. Anyone manage to install rgdal on R 2.14.0 on a mac (Standard app, not self compile or anything like that)?

    • I haven’t tried although I think my students were struggling still…

  11. Yes – I gave in the end and re-installed R 2.13.2. It works on command line R64 in 2.14 though. We need to wait to see if Kyngchaos produces something specifically for 2.14 …

  12. Regarding today’s comment:


    to install rgdal on Mac R 2.14.0 worked fine for me…

  13. … but beware cut-and-paste from this blog – the ‘smart quotes’ don’t give R the correct characters!

  14. Hi all

    on OS Lion 10.7.4

    R version 2.15.1 (2012-06-22)
    Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

    install.packages() worked without any problems at all for me, both



  1. Handling Spatial Data with R - [...] maptools, rgdal (Mac users may wish to see here first). [...]
  2. Exporting KML from R - [...] maptools, rgdal (Mac users may wish to see here first). [...]
  3. Paikkatieto, rajapinnat ja soRvi: osa 1 | Louhos - [...] olla asenettuna. Paketin asentaminen on ollut hankalaa etenkin Macilla, asennusohjeita löytyy täältä ja täältä. Lisäksi karttojen visualisointiin käytetään raster-pakettia,…

Post a Reply

Your email address will not be published. Required fields are marked *