I have seen this question here: Error in loading rgl package with Mac OS X but there is no mentioning about installation error, which is my case. I cannot install rgl<
On CentOS, what finally did the trick was installing libpng-dev:
sudo yum install libpng-devel.x86_64
Prior to this, I installed xorg, libx11, the mesa GL library, and freeglut.
sudo yum install xorg-x11-server-Xvfb.x86_64 xorg-x11-server-devel.x86_64
sudo yum install libX11.x86_64 libX11-devel.x86_64
sudo yum install mesa-libGL mesa-libGL-devel mesa-libGLU mesa-libGLU-devel
sudo yum install freeglut.x86_64 freeglut-devel.x86_64
The way I finally figured out what was missing was to try compiling from source (download the tar.gz at cran), and examining the config.log after ./configure failed.