32

How can I install a new version of R in my own directory, e.g., /local/data/project/behi.

  • 1
    You might be able to do so by starting from source; but if you have to ask, I'd guess yu aren't up to doing so. Please tell us what system you are running, and why you are interested in a new version. – vonbrand Aug 9 '14 at 22:50
  • Version specific installation using source code is much different than the installation using YUM or APT. It depends on OS version and the number of dependencies that need to be met for the installation to complete successfully. I have documented the installation of R 3.3.3 on SLES11 SP3 in hashprompt.blogspot.com/2017/06/… Hope that it might help you install on linux systems. – Baban Gaigole Jun 22 '17 at 0:34
41

The easiest way to do this is to install R from source:

$ wget http://cran.rstudio.com/src/base/R-3/R-3.4.1.tar.gz
$ tar xvf R-3.4.1.tar.gz
$ cd R-3.4.1
$ ./configure --prefix=$HOME/R
$ make && make install

The second-to-last step is the critical one. It configures R to be installed into a subdirectory of your own home directory.

To run it on Linux, macOS and similar systems, add $HOME/R/bin to your PATH. Then, shell commands like R and Rscript will work.

On macOS, you have another alternative: build R.app and install it into your user's private Applications folder. You need to have Xcode installed to do this.

You might consider giving --prefix=$HOME instead. That installs R at the top level of your home directory, so that the R and Rscript binaries end up in $HOME/bin, which is likely already in your user's PATH. The downside is that it makes later uninstallation harder, since R would be intermingled among your other $HOME contents.

(If this is the first thing you've installed to $HOME/bin, you might have to log out and back in to get this in your PATH, since it's often added conditionally only if $HOME/bin exists at login time.)

This general pattern applies to a large amount of Unix software you can install from source code. If the software has a configure script, it probably understands the --prefix option, and if not, there is usually some alternative with the same effect.

These features are common for a number of reasons. In decreasing order of likelihood, in my experience:

  • The safe default (/usr/local) is not the right $prefix in all situations. Circumstances might dictate something else such as /usr, /opt/$PKGNAME, etc.

  • Binary package building systems (RPM, DEB, PKG, Cygport...) typically build and install the package into a special staging directory, then pack that up in such a way that it expands into the desired installation location.

  • Your case, where you can't get root to install the software into a typical location, so you install into $HOME instead.

  • 1
    I would recommend ./configure --prefix=$HOME/R --enable-R-shlib to make sure you compile R shared library. Otherwise, RStudio will complain. – akhmed Feb 12 '17 at 2:07
  • Didn't work me. Script ended with configure: error: --with-readline=yes (default) and headers/libs are not available make: *** No targets specified and no makefile found. Stop. – ApproachingDarknessFish Oct 19 '17 at 17:38
  • @ApproachingDarknessFish: That has nothing to do with this question or my answer. You're missing necessary prerequisites for building R on your system with your chosen options. Specifically here, you're missing the readline development libraries. If you have more problems, post a new question. – Warren Young Oct 19 '17 at 17:46
8

You can also use the wrapper application Renv.

excerpt

Simple R Version Management: Renv

Renv lets you easily switch between multiple versions of R. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.

Renv does…

  • Let you change the global R version on a per-user basis.
  • Provide support for per-project R versions.
  • Allow you to override the R version with an environment variable.
1

Build from source with ./configure --prefix=/local/data/project/behi ; make ; make install

If you're installing from an RPM package and it was created relocatable, you could use

rpm ... --prefix /local/data/project/behi

But not all packages are built with relocatable binaries, and I don't think debian packages have this option (although you might succeed with dpkg --instdir).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.