如何让 linux 识别 R 的位置

How to get linux to recognize where R is located

我确信这是一个微不足道的问题,但我正在尝试在 Linux 中安装多个 R 版本。我没有使用 R studio server pro,而是使用免费的 R studio server。我按照这个 documentation 安装了 R,但是当我试图找到它时出现了错误。但是,当我运行命令查看安装了哪个版本的R时,没有报错。

R 已安装!

(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/.

尝试次数

(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$ 

重现步骤

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'

你把它复杂化了。只需安装

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

然后将$PATH设置到你想要的版本的bin/目录,或者直接调用R。这几乎正​​是我们许多人使用两个版本的 R(即 R-release 和 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"
$ 

前两个和我的'default'版本一样。第三个是我的候补。这就是它的全部内容。