I had a few hurdles to get through when trying to install the “rgl” R package in Ubuntu. In summary, here was my solution:

From the terminal:

sudo apt-get install r-cran-dev xorg-dev libglu1-mesa-dev

Then from R:

install.packages("rgl")

 Detailed Log

The first snag I hit was the following implying I was missing some necessary X code:

checking for X... no
configure: error: X11 not found but required, configure aborted.
ERROR: configuration failed for package ‘rgl’

You’ll need the `xorg-dev` package to get around this issue. I then hit an error regarding a `GL` library:

checking for X... libraries , headers
checking GL/gl.h usability... no
checking GL/gl.h presence... no
checking for GL/gl.h... no
checking GL/glu.h usability... no
checking GL/glu.h presence... no
checking for GL/glu.h... no
configure: error: missing required header GL/gl.h
ERROR: configuration failed for package ‘rgl’

A quick Google showed that the `libglu1-mesa-dev` package contained these headers. Once I had installed those package, the install process went smoothly!

Note, too, that there may be a precompiled package may be available for your distribution under the name r-cran-rgl. In my case, I needed a more recent version of the package than was offered there, hence this exploration.