一、安装 R 与 R Studio
快速使用
# update indices
sudo apt update -qq -y
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr -y
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Fingerprint: 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
# add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" -y
sudo apt install --no-install-recommends r-base -y
sudo apt-get install gdebi-core -y
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2024.04.2-764-amd64.deb
sudo gdebi rstudio-server-2024.04.2-764-amd64.deb -n
rm rstudio-server-2024.04.2-764-amd64.deb
sudo chmod -R a+rw /usr/lib/R/library
sudo chmod -R a+rw /usr/share/R/
以上代码可直接复制使用,以下为代码细节
安装R
首先下载CRAN仓库的官方密钥,并将官方仓库添加到系统镜像源。若CRAN发布最新R版本,请参考官方安装文档
# update indices
sudo apt update -qq -y
# install two helper packages we need
sudo apt install --no-install-recommends software-properties-common dirmngr -y
# add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Fingerprint: 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
# add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" -y
然后可以直接使用apt安装R
sudo apt install --no-install-recommends r-base -y
安装R studio
若Ubuntu发布最新版本,请参考[官方安装文档](RStudio Server – Posit)是否需更换最新安装程序
#安装某个轻量级dpkg包管理软件,其实这一步可以不用
sudo apt-get install gdebi-core -y
#下载Ubuntu版本的Rstudio的预编译.deb包
wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-2024.04.2-764-amd64.deb
#安装软件
sudo gdebi rstudio-server-2024.04.2-764-amd64.deb -n
#删除安装包
rm rstudio-server-2024.04.2-764-amd64.deb
设置权限
在Ubuntu下R包安装时默认没有某些关键文件夹的权限,需要手动开放
#添加下面两个目录对所有用户的读写权限
sudo chmod -R a+rw /usr/lib/R/library
sudo chmod -R a+rw /usr/share/R/
至此安装完成
二、Linux下依赖安装
编译链——所有R包源码安装都依赖
sudo apt install make cmake gcc g++ -y
生物信息学
sudo apt install libxml2-dev liblapack-dev libpng-dev zlib1g-dev libcurl4-openssl-dev gfortran -y
GEOquery依赖:libxml2-dev、liblapack-dev、libpng-dev、libcurl4-openssl-dev、gfortran
Seurat依赖:zlib1g-dev、libcurl4-openssl-dev、gfortran、libpng-dev
画图包
sudo apt install libgmp-dev
ggstatsplot依赖:libgmp-dev、libmpfr-dev