admin 管理员组

文章数量: 1103785

01 Ubuntu 22.04 安装Anaconda+配置R语言&RStudio

01 Ubuntu 22.04 安装Anaconda+配置R语言&RStudio

一、软硬件环境

终端中输入uname -a 查看本机信息

主要信息:

  • Linux:表示这是一个基于 Linux 的操作系统。
  • GF65-Thin-9SEXR:本台计算机的主机名
  • 5.19.0-32-generic:Linux 内核的版本号
  • 22.04.1:系统版本
  • x86_64:基于x86架构的64位处理器

二、安装Anaconda

1. 下载Anaconda

Anaconda官方网站:The Operating System for AI

官方源下载:

代码语言:txt复制
wget .03-Linux-x86_64.sh

清华tuna镜像下载:

代码语言:txt复制
wget .03-Linux-x86_64.sh

2. 安装Anaconda

在终端进入对应的下载目录,输入命令:

bash Anaconda3-2023.03-Linux-x86_64.sh

提示You can undo this by running conda init --reverse $SHELL 输入 yes

3. 添加环境变量

终端输入命令:

sudo gedit ~/.bashrc

在最后一行添加:export PATH="/home/yz/anaconda3/bin:$PATH"

其中/home/yz/anaconda3要替换成你自己的安装路径

保存后退出

4. 验证安装

新开终端,输入:

source ~/.bashrc

此时终端会显示进入conda的base环境

再输入:

conda -V

终端会显示Anaconda版本号

三、配置Anaconda

1. 添加虚拟环境

启动Anaconda:

conda activate

查看python版本(我的是3.12.3):

python --version

添加虚拟环境:

conda create -n rnaseq python=3.12.3

查看所以环境:

conda info -envs

2. 配置conda镜像源

启动rnaseq环境:

conda activate rnaseq

使用命令:

conda config --add channels xxx

清华tuna:

代码语言:txt复制
conda config --add channels /
conda config --add channels /
conda config --add channels /
conda config --add channels /
conda config --set show_channel_urls yes
conda config --set channel_priority flexible

查看源:

conda config --show-sources

退出conda环境:

conda deactivate rnaseq

conda deactivate base

四、R语言相关工具下载与安装

1. 安装R语言工具包

官网:The Comprehensive R Archive Network

点击Ubuntu版本

官网显示只有Ubuntu的LTS版本才有R语言的全面支持

按照官网说明依次运行命令:

sudo apt update -qq

sudo apt install --no-install-recommends software-properties-common dirmngr

wget -qO- .asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

sudo add-apt-repository "deb $(lsb_release -cs)-cran40/"

sudo apt install --no-install-recommends r-base

即可完成安装

2. 安装RStudio

RStudio是一种R语言编译器,官网:A better way to deploy R & Python

点击DOWNLOAD RSTUDIO

下拉选择点击Free版本的Download,在弹出的页面中找到对应的版本

下载完成后进入对应的文件目录,打开终端

sudo dpkg -i rstudio-2024.09.0-375-amd64.deb

如果遇到报错,输入:

sudo apt --fix-broken install

再次安装:

sudo dpkg -i rstudio-2022.07.2-576-amd64.deb

在开始界面中能显示图标,即安装完成:

3. 修改R包源

打开终端,进入/etc/R/,输入:

sudo gedit Rprofile.site

文件的最后一段是这样的:

代码语言:txt复制
## We set the cloud mirror, which is 'network-close' to everybody, as default
local({
    r <- getOption("repos")
    r["CRAN"] <- ";
    options(repos = r)
})

修改r["CRAN"]部分,将R包源改为tuna镜像源,并添加tuna的BioC源,最后再添加对于下载方式的设定:

代码语言:txt复制
## We set the cloud mirror, which is 'network-close' to everybody, as default
local({
    r <- getOption("repos")
    r["CRAN"] <- "/"
##  r["BioC_mirror"] <- "/"
    options(repos = r)
})
options(BioC_mirror="/")

options("download.file.method"="libcurl")
options("url.method"="libcurl")

保存并退出

4. 验证源更换

在RStudio控制台界面输入options()$reposoptions()$BioC_mirror,查看输出结果,如果源已更换,则验证成功:

至此,所以安装和配置均告完成

本文标签: 01 Ubuntu 2204 安装Anaconda配置R语言ampRStudio