系统:linux/ubuntu
权限:root权限执行
参考网址:Ubuntu Packages For R - Full Instructions (r-project.org)
How to update R 3.x to the new R 4.x in Linux Ubuntu | by Henrique Gomide, Ph.D. | Medium
(1)查看R安装源版本
看到网上大部分教程都是直接apt install r-base
这里需要注意apt r源版本, apt 安源源在配置文件:/etc/apt/sources.list中,可以定义添加
查看R安源源版本,代码如下: #执行其一即可
apt search r-base |grep "^r-base"
apt policy r-base
r-base:
Installed:(none)
Candidate: 3.6.3-1bionic
Version table:
3.6.3-1bionic 500
500 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages
500 http://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/ Packages
3.6.2-1bionic 500
500 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages
500 http://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/ Packages
3.6.1-3bionic 500
500 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages
500 http://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/ Packages
3.6.1-1bionic 500
500 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages
500 http://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/ Packages
3.6.0-2bionic 500
500 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/ Packages
500 http://cran.rstudio.com/bin/linux/ubuntu bionic-cran35/ Packages
...................
查看
cat /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security multiverse
deb https://cloud.r-project.org/bin/linux/ubuntu/ bionic-cran35/
#deb https://cloud.r-project.org/bin/linux/ubuntu/ bionic-cran40/
deb http://cran.rstudio.com/bin/linux/ubuntu/ bionic-cran35/
根据以上可知道 R安装源库版本为cran35, 注意不同ubuntu版本,对应的代号
ubuntu1~18.04: bionic
Ubuntu 20.04 LTS: focal
(2)升级 apt R安装源或者修改R安装源
方案1:
apt update
apt search r-base |grep "^r-base"
如果已经有目的安装R版本,之后直接执行安装代码
apt install r-base # 建议配合安装rstudio-server ,而非rstudio
方案2:
sudo vi /etc/apt/sources.list #系统文件修改,需要root 权限
注释掉bionic-cran35信息行,添加新的信息源(从官网查找:Ubuntu Packages For R - Full Instructions (r-project.org))
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security multiverse
#deb https://cloud.r-project.org/bin/linux/ubuntu/ bionic-cran35/
deb https://cloud.r-project.org/bin/linux/ubuntu/ bionic-cran40/
deb http://cran.rstudio.com/bin/linux/ubuntu/ bionic-cran40/
#deb http://cran.rstudio.com/bin/linux/ubuntu/ bionic-cran35/
然后apt search r-base |grep "^r-base" 命令查看apt install r-base
有需要的安装R版本之后,执行安装命令
如果存在连结R源库地址失败问题,可能是没有获得安装R源网址权限,可以尝试添加一个权限密钥:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
(3)升级R包
升级完成后,打开R,执行以下命令,完成R包的升级
update.packages(ask = FALSE, checkBuilt = TRUE)