Compiling R with GNU Readline

Updated 2018 March 23rd for R-3.4.4

I use a lot of shortcuts provided by GNU Readline. I recently compiled R without Readline support and it was almost unusable! This was because I ran into the error:

configure: error: --with-readline=yes (default) and headers/libs are not available

To circumvent this I compiled R by running:

./configure --with-readline=no --with-x=no

and I do not recommend it.

To fix this, I downloaded and compiled the latest GNU Readline source.

# I have a source directory in my home directory
cd ~/src
wget -c -N
tar -xzf readline-7.0.tar.gz
cd readline-7.0/
./configure --prefix=`pwd`
make install

Now download the latest version (as of this writing) of the R source.

cd ~/src
wget -c -N
tar -xzf R-3.4.4.tar.gz
cd R-3.4.4/

Add these two lines to the file but change /home/dtang to your own home directory (or where ever you downloaded and compiled Readline).


In addition, we need to define the LD_LIBRARY_PATH environmental variable to the directory of the readline libraries. Despite specifying -L, the GNU linker (ld) does not look in the specified directory. Once again, change /home/dtang accordingly.

# run this line in the terminal
export LD_LIBRARY_PATH=/home/dtang/src/readline-7.0/lib/

Now R should happily compile (if you're not missing more libraries; see below).

# note I don't use the X Window System
./configure --prefix=`pwd` --with-x=no --enable-R-shlib=yes
make install


If you get the error: "Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error)", run capabilities().

No protocol specified
       jpeg         png        tiff       tcltk         X11        aqua    http/ftp     sockets      libxml 
       TRUE        TRUE        TRUE        TRUE       FALSE       FALSE        TRUE        TRUE        TRUE 
       fifo      cledit       iconv         NLS     profmem       cairo         ICU long.double     libcurl 
       TRUE        TRUE        TRUE        TRUE       FALSE        TRUE        TRUE        TRUE        TRUE

You will need to compile with "--with-cairo=yes" and have "cairo-devel" and "pango-devel" installed.

sudo yum install cairo-devel pango-devel

On a clean installation of RHEL7, these should be all the required headers for compiling R-3.5.1.

sudo yum install readline-devel

# "X11 headers/libs are not available"
sudo yum install libXt-devel

sudo yum install zlib-devel
sudo yum install bzip2-devel
sudo yum install xz xz-devel
sudo yum install pcre-devel
sudo yum install libcurl-devel
sudo yum reinstall libcurl curl libcurl-devel
sudo yum install cairo-devel pango-devel libpng-devel
sudo yum install java-1.8.0-openjdk-devel

sudo mkdir -p /opt/R/3.5.1
./configure --prefix=/opt/R/3.5.1 --with-x=yes --enable-R-shlib=yes --with-cairo=yes --with-libpng=yes
sudo make install

Lastly, create an .Rprofile file in your home directory and set .libPaths to specify where you want to install your R packages.

Print Friendly, PDF & Email

Creative Commons License
This work is licensed under a Creative Commons
Attribution 4.0 International License
3 comments Add yours

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.