I am pretty new to Linux. I installed R-base in my Ubuntu 12.04 using the Software Center (which by default is r-2.14). I want to upgrade to/install R 3.02 or newer. How can I do that? Thank you.
4 Answers
You need to add R's repository to your system:
Use your favorite text editor (I'm using
geditas an example) to open/etc/apt/sources.list:sudo -H gedit /etc/apt/sources.listAdd this line to the file (if this is slow, use another mirror. You may also want to change
preciseinto the codename for your Ubuntu version --- e.g.,trustyfor 14.04):deb http://cran.rstudio.com/bin/linux/ubuntu precise/Update the list of packages
sudo apt-get updateInstall the latest R-base (you can also use the software center again):
sudo apt-get install r-base
Having had to spend time figuring this out and forgetting how it works, and then having to figure it out again multiple times, here's a more complete answer that is future-proof.
Edit the
sources.listfile. This file contains the servers thatapt-getconsults to check whether software exists and where it can be downloaded from. One can edit the file using the following command:sudo -H gedit /etc/apt/sources.listThis requires the gedit editor. If you get an error, either install this (
sudo apt-get install gedit) or use another editor like nano (sudo nano /etc/apt/sources.list).Find a working server to download R from that also has the version of R you are interested in. This often means that one has to look for the name of the latest Ubuntu release. A list of releases is maintained on the Ubuntu website. Look for the latest released version and use only the first word in its name without capitalization. For instance, for the 16.04 release, the full name is
Xenial Xerusand the name to use is thusxenial. Thus, we add the following line to thesources.list:deb http://cran.rstudio.com/bin/linux/ubuntu xenial/Note that the above line uses the rstudio.com mirror. One can choose another mirror from this long list and appropriately alter the URL. For instance:
deb http://mirrors.dotsrc.org/cran/bin/linux/ubuntu xenial/Save and close the file. After this, one can install the newest version using:
sudo apt-get update # update apt-get's list of known releases sudo apt-get install r-base # install the newest available version of R
- 207,228
- 424
The answers so far are useful but they all omit the next step which is pretty much going to be required of anyone who intends to use R seriously. Quoted lines are from the canonical R Installation and Administration Manual:
Users who need to compile R packages from source [e.g. package maintainers, or anyone installing packages with install.packages()] should also install the r-base-dev package:
sudo apt-get install r-base-dev
I think potential installers should be reading that Manual more carefully than the recommendations on this page have so far advised.
- 125