進來直接點擊
https://zhuanlan.zhihu.com/p/570310639
http://www.itdecent.cn/p/9a249696295f
引用上述
1.下載安裝R
#?根據(jù)R官網(wǎng)(The Comprehensive R Archive Network)終端運行。
#更新索引
sudo apt update -qq
#安裝我們需要的兩個helper包
sudo apt install --no-install-recommends software-properties-common dirmngr
#為這些回購添加簽名密鑰(由Michael Rutter編寫)
#要驗證密鑰,請運行g(shù)pg--show keys/etc/apt/trusted.gpg.d/cran_ubuntu_key.asc公司
#指紋:E298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
#添加CRAN的R 4.0回購——根據(jù)需要將“focus”調(diào)整為“groovy”或“bionic”
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
#安裝R及其依賴
sudo apt install --no-install-recommends r-base
#輸入以下命令分別修改Bioconductor和CRAN的默認(rèn)鏡像源(方便以后安裝R包)
echo -e 'options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")\noptions("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))' >> ~/.Rprofile
2. RStudio-Server安裝
# 創(chuàng)建一個文件夾存放deb包,你也可以放在你常用的路徑下
mkdir Software
# 進入剛創(chuàng)建的文件夾
cd Software
# 下載rstudio-server安裝包
wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2023.03.0-386-amd64.deb
# 安裝gdebi工具
sudo apt install-y gdebi-core
# 安裝rstudio-server
sudo gdebi rstudio-server-2023.03.0-386-amd64.deb
3.下載安裝R第三方包
#?方法一:普通包可以在Rstudio使用install.packages()
install.packages("packagename")
#?方法二:在Rstudio中使用BiocManager::install()
if (!require("BiocManager", quietly = TRUE))
? ? install.packages("BiocManager")
BiocManager::install()
BiocManager::install("packagename")
#方法三:終端下載R包
#遇上某些在Rstudio中下載到一半總是中斷的R包(不是安裝編碼出錯,而是下載出錯),報錯信息會拋出這個包的網(wǎng)址,提示下載出錯??梢栽诮K端輸入wget 該包的網(wǎng)址。#下載R包
wget 包的網(wǎng)址? ? ? ? ??
下載完后打開Rstudio,按下圖操作。
選擇Package Archive file,接著Browse找到剛下載的R包,最后Install.
最后安裝R包是最讓人沮喪且耗費體力的一項工作之一,原因絕大多數(shù)與Ubuntu是一個很干凈的系統(tǒng),缺少許多R包安裝的工具。按照上述三種方法安裝R包,如果你的Ubuntu是剛安裝不久,系統(tǒng)一定會缺少許多文件,不支持你安裝某些R包。但慶幸的是這也容易解決(只是耗時間),在安裝的過程中留意報錯信息,找到有“error“,“建議執(zhí)行某命令“的字樣。然后解決的基本原則是報錯信息里提示缺少哪個文件就安裝這個文件(sudo apt install 文件名);報錯信息建議你執(zhí)行某個命令,在終端執(zhí)行這條命令。