Wednesday, October 9, 2013

How to install and upgrade R up to date on Ubuntu linux

Installation of R on Ubuntu : 
  • R is included as part of the standard Ubuntu distribution, and can be installed with a command like  
    • sudo apt-get install r-base
  • Installation location of R and Library file
    • Installed location : /usr/lib/R 
    • Library file : /usr/local/lib/R /usr/share/R /etc/R /usr/bin/R
  • Open Terminal and simply type R to open the shell
  • Set the Environmental variable for R Systems in ./bashrc file
    • export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.35
    • export PATH=$JAVA_HOME/bin:$PATH
    • export R_HOME=/usr/lib/R
    • export PATH=$R_HOME/bin:$PATH
    • export LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib:/usr/lib/R/lib:/usr/lib/jvm/java-6-sun-1.6.0.35/lib:/usr/lib/jvm/java-6-sun-1.6.0.35/jre/lib/amd64/server:/usr/local/lib/R/site-library/rJava/jri
    • export PATH=$LD_LIBRARY_PATH/bin:$PATH
  • Use below command to reconfigure/update the R Systems
    • sudo R CMD javareconf
  • Obviously the software included as part of the standard distribution usually lags a little behind the latest version, and this is usually quite acceptable for most users most of the time. However, R is evolving quite quickly at the moment, and for various reasons I have decided to skip Ubuntu 12.10 (quantal) and stick with Ubuntu 12.4 (precise) for the time being. Since R 2.14 is included with Ubuntu 12.4, and I’d rather use R 2.15, I’d like to run with the latest R builds on my Ubuntu system.
  • Fortunately this is very easy, as there is a maintained repository for Ubuntu builds of R on CRAN. Full instructions are provided on CRAN, but here is the quick summary. First you need to know your nearest CRAN mirror – there is a list of mirrors on CRAN. I generally use the Bristol mirror, and so I will use it in the following.
Upgrade the R on Ubuntu : 
    • sudo su
    • echo "deb http://lib.stat.cmu.edu/R/CRAN/bin/linux/ubuntu precise/" >> /etc/apt/sources.list
    • apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
    • apt-get update
    • apt-get upgrade
  • That’s it. You are updated to the latest version of R, and your system will check for updates in the usual way. There are just two things you may need to edit in line 2 above. The first is the address of the CRAN mirror (here “http://lib.stat.cmu.edu/R/CRAN”). The second is the name of the Ubuntu distro you are running (here “precise”).

12 comments: