Home > Software engineering >  How to get linux to recognize where R is located
How to get linux to recognize where R is located

Time:05-26

I am sure this is a trivial question, but I am trying to install multiple R versions in Linux. I am not using R studio server pro and am instead using the free R studio server. I followed this documentation to install R but got errors when I attempted to locate it. However, when I run a command to see what version of R is installed, there is no error.

R is installed!

(base) noah@noah-VirtualBox:/opt/R/4.1.3$  /opt/R/4.1.3/bin/R --version
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

Attempts

(base) noah@noah-VirtualBox:/opt/R/4.1.3$ R

Command 'R' not found, but can be installed with:

sudo apt install r-base-core
(base) noah@noah-VirtualBox:/opt/R/4.1.3$ which R
(base) noah@noah-VirtualBox:/opt/R/4.1.3$ 

Steps to reproduce

export R_VERSION=4.1.3

curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
# Build and install R
./configure \
    --prefix=/opt/R/${R_VERSION} \
    --enable-memory-profiling \
    --enable-R-shlib \
    --with-blas \
    --with-lapack
make
sudo make install
# Verify R installation
/opt/R/${R_VERSION}/bin/R --version
# Create a symlink to R
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
# Export path so Rstudio can find it
export RSTUDIO_WHICH_R='/opt/R/4.1.3/bin'

CodePudding user response:

You are overcomplicating it. Just install in, say,

/opt/R/4.2.0/
/opt/R/4.1.2/
/opt/R/4.0.5/

and then either set the $PATH to the bin/ directory in the version you want, or call R directly. It is what pretty much exactly what many of us have done with two versions of R (i.e. R-release and R-devel):

$ R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$ 
$ /usr/lib/R/bin/R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$ 
$ /usr/local/lib/R-devel/bin/R --version | head -1
R Under development (unstable) (2022-05-24 r82398) -- "Unsuffered Consequences"
$ 

The first two are the same as that is my 'default' version. The third is my one alternate. And that is all there is to it.

  • Related