35

How to install the R language interpreter? What is the package name? I have tried R, rlang, Rlang, rproject, etc. but nothing works - neither apt-get nor Ubuntu Software Centre found R.

Is it possible that R is not included in the official Ubuntu repositories?

amc
  • 7,142

3 Answers3

43

Package you are asking of is r-base. So run the following command:

sudo apt-get install r-base

and you will have R in your system. Years ago I was also confused by this - such package name is stupid indeed.

26

The package you want is r-base Install r-base.

If you need to build R packages from source, you also need r-base-dev Install r-base-dev. (Most users probably don't need this.)

That's likely all you need to do.

Getting newer versions of R

The version of R probably your Ubuntu release's official software sources is likely sufficient. Assuming that's the case, you needn't read any further (except perhaps for entertainment).

But if you want/need the latest version, choose a CRAN mirror from the list. The do one of the following:

  • Make a .list file (you might call it r.list) in /etc/apt/sources.list.d with this line as its contents:

    deb http://your-cran-mirror/bin/linux/ubuntu trusty/

    If you're using Ubuntu 14.04 Trusty Tahr, you'll keep trusty as it is. Otherwise replace that word with the lower-case codename of whatever Ubuntu release you're using. (The first word only; the "adjective", not the "animal name".) They are listed here or on the releases page. For example, for Ubuntu 12.04 Precise Pangolin it is precise. For 14.10 Utopic Unicorn it will be utopic.

    This is the name listed in most or all of the similar deb lines in the configuration file /etc/apt/sources.list.

    To make your r.list file, you can open a Terminal windows (Ctrl+Alt+T) and run a command like this (making sure to substitute in your CRAN mirror of choice, and, if you're not running 14.04, your release codename):

    echo 'deb http://your-cran-mirror/bin/linux/ubuntu trusty/' | sudo tee -a /etc/apt/sources.list.d/r.list

    For example, on an Ubuntu 15.04 Vivid Vervet system located in the northeastern United States, I used:

      echo 'deb http://cran.mirrors.hoobly.com/bin/linux/ubuntu vivid/' | sudo tee -a /etc/apt/sources.list.d/r.list
    
  • Or, instead of adding the software source in its own configuration file, add that line to the master software sources configuration file, /etc/apt/sources.list. You can open that file up in a graphical text editor by opening a Terminal window (Ctrl+Alt+T) and running the command:

      sudo -H gedit /etc/apt/sources.list
    

Add the signing key for the CRAN repositories (you can verify it here):

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

If that fails, this way may work:

gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -

To activate the new software sources configuration, run:

sudo apt-get update

Then to install (or upgrade to) the version of R for CRAN:

sudo apt-get install r-base

(You can install r-base-dev and any other needed packages similarly. sudo apt-get upgrade will typically upgrade any R packages that have newer versions, if an older version is installed; you don't have to enter their names individually.)

Further reading / source cited:

For more details and information about other supporting packages available for installation on Ubuntu systems, see "UBUNTU PACKAGES FOR R".

  • The above answer is (very) loosely adapted from (a small) part of that README.
  • The commands for importing the CRAN signing key are drawn directly from it, though my instructions are in my own words, and simplified.
Eliah Kagan
  • 117,780
  • Adding the above line in sources.list results in an error saying the line is incorrectly formatted. The below thread says that this is the correct format to add the source name

    "deb http://stat.ethz.ch/CRAN/bin/linux/ubuntu trusty/ #enabled-manually"

    http://askubuntu.com/questions/503270/problem-with-project-r-installation

    Please correct me if I am wrong. I am a newbie, but this worked for me.

    – Erdnase Aug 26 '14 at 14:40
  • @Erdnase Sorry! You're right about the / after the release name. I've added that to this post--thanks! (The part starting with # is a commen and is optional.) – Eliah Kagan Aug 26 '14 at 15:18
  • Your images need updating. – Tim May 08 '15 at 13:50
  • @Tim What images? – Eliah Kagan May 08 '15 at 14:07
  • @The install r-base ones? Maybe it's my school blocking them. – Tim May 08 '15 at 14:10
  • @Tim Oh. Is it just the images, or the links also? The images load fine for me, but it may be a good idea anyway for me to change them to (a) use a direct HTTPS link, and (b) use an image hosted on stack.imgur.com to minimize the likelihood of them ever going down in the future. Currently they redirect though http://hostmar.co/software-small to https://i.imgur.com/uRtxs.png (I used this method). In some of my more recent posts, I've been using https://i.stack.imgur.com/vgiqp.png in place of http://hostmar.co/software-small. Does that load for you? – Eliah Kagan May 08 '15 at 14:25
  • @EliahKagan they load at home as are. At school i.stack.imgur is unblocked - I specifically requested. It wouldn't hurt to have them all on the same domain! Atually if I go to hostmar.co in my browser, they're blocked by my spam / abusive / adult blocker, but the images load. May be sensible to have i.stack :) – Tim May 08 '15 at 21:08
  • @Tim Images updated. – Eliah Kagan May 11 '15 at 20:47
  • How do I install all CRAN, Bioconductor, Omegahat, ... packages that are available in the repository? Is there a meta-package? So far I've found only (apt-cache search r-cran-; apt-cache search r-omegahat-; apt-cache search r-bioc-) | cut -d " " -f 1 | grep -v r2jags | xargs apt-get install -y which won't catch new packages as they are included in the Debian archive. – krlmlr Jan 28 '16 at 11:05
1

Edit: It is included in the Ubuntu repositories, but they want you to install from theirs.

Source.

UBUNTU PACKAGES FOR R

R packages for Ubuntu on i386 and amd64 are available for all stable Desktop releases of Ubuntu until their official end of life date. However, only the latest Long Term Support (LTS) release is fully supported. As of October 17, 2013, the supported releases are Trusty Tahr (14.04), Precise Pangolin (12.04; LTS), and Lucid Lynx (10.04; LTS).

See here for details.

INSTALLATION

To obtain the latest R packages, add an entry like

  deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu trusty/

or

  deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu precise/

or

  deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu lucid/

in your /etc/apt/sources.list file, replacing by the actual URL of your favorite CRAN mirror. See here for the list of CRAN mirrors. To install the complete R system, use

  sudo apt-get update
  sudo apt-get install r-base

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 (Not relevant to you, added for clarity):

  sudo apt-get install r-base-dev
Tim
  • 32,861
  • 27
  • 118
  • 178
  • Well, according to your source, it looks like someone in R development team don't want us to install R from Ubuntu repository. There is a package in Ubuntu repository: r-base. –  Aug 04 '14 at 07:20
  • If you want to download R and install it, then you have to get funky about adding the public key of the R package server like this answer: http://askubuntu.com/questions/503270/problem-with-project-r-installation/503298#503298 – karel Aug 04 '14 at 07:25
  • If you don't add the public key then you can't install R. The terminal will, however, give you a message asking you to add the public key before you install R and if you add the public key then r-base can be installed successfully afterwards. – karel Aug 04 '14 at 07:35
  • All the information that you need to add the public key is detailed in the link given in my first comment. I can also confirm that the information in the linked answer is current and it works for installing the r-base package in Ubuntu 14.04. – karel Aug 04 '14 at 07:40