系統(tǒng):linux/ubuntu
權限:root權限執(zhí)行
參考網(wǎng)址: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安裝源版本
看到網(wǎng)上大部分教程都是直接apt install r-base
這里需要注意apt r源版本, apt 安源源在配置文件:/etc/apt/sources.list中幸海,可以定義添加
查看R安源源版本聘裁,代碼如下:? ? ? ? ? ? ? #執(zhí)行其一即可
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/
根據(jù)以上可知道 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"?
如果已經(jīng)有目的安裝R版本踊跟,之后直接執(zhí)行安裝代碼
apt install r-base # 建議配合安裝rstudio-server ,而非rstudio
方案2:
sudo vi?/etc/apt/sources.list? #系統(tǒng)文件修改锹淌,需要root 權限
注釋掉bionic-cran35信息行摔吏,添加新的信息源(從官網(wǎng)查找: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版本之后,執(zhí)行安裝命令
如果存在連結(jié)R源庫地址失敗問題米罚,可能是沒有獲得安裝R源網(wǎng)址權限,可以嘗試添加一個權限密鑰:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
(3)升級R包
升級完成后丈探,打開R录择,執(zhí)行以下命令,完成R包的升級
update.packages(ask = FALSE, checkBuilt = TRUE)