安装Miniconda,这里用的是清华镜像源:Index of /anaconda/miniconda/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirrorhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
按时间排序,选择最新的Linux-x86_64.sh,右击复制链接
。
在用户目录下下载。
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
等待。下载完成后用bash
安装。
bash Anaconda3-2020.07-MacOSX-x86_64.sh
安装时需要一些同意。按需要进行<enter>
或者输入yes
。
Please, press ENTER to continue
>>> <enter>
······
--More--
······
Do you accept the license terms? [yes|no]
[no] >>>
Please answer 'yes' or 'no':'
>>> yes
下一步为安装位置确认,位置默认为用户目录下的anaconda3
文件夹。
Anaconda3 will now be installed into this location:
/home/test/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/test/anaconda3] >>>
一般选择默认路径,如想更改在后面输入自己想添加到的路径位置即可。如:/home/data/conda3 ,直接<enter>
。
下一步为是否init
。init
能够帮助你解决环境变量的问题。所以依旧yes
。
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
conda config --set auto_activate_base false
Thank you for installing Anaconda3!
安装完毕之后,重连服务器或者运行
. ~/.bashrc
,之后会出现,(base) [test@VM-0-7-centos ~]$
。
前面的(base)
表明你已经激活anaconda3
的base
环境,使用conda config --set auto_activate_base false
可以阻止该环境的自动激活。
按照清华镜像的 anaconda help 配置镜像地址。
在用户目录下新建.condarc
文件。
cd ~
vim .condarc
<i>
输入以下内容。
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
保存。
<:>
<w>
<q>
<enter>
此时查看config
内容,可以看到默认channel
(镜像)已经改变。
conda config --show
之后也可以再添加一些其他想要的镜像源,比如直接在conda里面输入如下代码即可:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
像删除已添加的镜像源,可以:
conda config --remove channels 源名称或链接
显示添加的源通道
显示添加的源通道
conda config --show-sources
安装R环境
新建一个环境Renv
,环境是为了避免版本及依赖冲突。
conda create --name Renv
提示中出现。
## Package Plan ##
environment location: /home/test/anaconda3/envs/Renv
Proceed ([y]/n)? y
environment location
表明了环境的存储位置。按y
同意。
安装结束后,激活该环境。
(base) [test@VM-0-7-centos etc]$ conda activate Renv
(Renv) [test@VM-0-7-centos etc]$
此时前缀更改为(Renv)
。
安装R
。
#查看镜像中是否有R4.0版本
conda search R
该命令表示从conda-forge
拉取4.0版本的r-base
进行安装,也可以选择3.6等其他版本。
conda install -c conda-forge r-base=4.0
可以看到依赖的库有点多。大致看一下。
The following packages will be downloaded:
package | build
---------------------------|-----------------
gcc_impl_linux-64-7.5.0 | hdb87b24_16 38.4 MB conda-forge
gcc_linux-64-7.5.0 | hf34d7eb_28 23 KB conda-forge
gfortran_impl_linux-64-7.5.0| h1104b78_16 9.0 MB conda-forge
gfortran_linux-64-7.5.0 | ha781d05_28 22 KB conda-forge
libgcc-ng-9.3.0 | h24d8f2e_16 7.8 MB conda-forge
libgfortran-ng-7.5.0 | hdf63c60_16 1.3 MB conda-forge
lz4-c-1.9.2 | he1b5a44_3 203 KB conda-forge
make-4.3 | h516909a_0 505 KB conda-forge
ncurses-6.2 | he1b5a44_1 993 KB conda-forge
openssl-1.1.1h | h516909a_0 2.1 MB conda-forge
pip-20.2.3 | py_0 1.1 MB conda-forge
pixman-0.38.0 | h516909a_1003 594 KB conda-forge
pthread-stubs-0.4 | h14c3975_1001 5 KB conda-forge
python-3.8.5 |h1103e12_8_cpython 22.0 MB conda-forge
python_abi-3.8 | 1_cp38 4 KB conda-forge
r-base-4.0.2 | he766273_1 23.6 MB conda-forge
zlib-1.2.11 | h516909a_1009 106 KB conda-forge
zstd-1.4.5 | h6597ccf_2 712 KB conda-forge
------------------------------------------------------------
Total: 230.0 MB
可以看到,环境在安装python
和r-base
的同时,也会安装gcc
gfortran
openssl
make
zlib
等常用系统库。所以Anaconda
解决系统依赖的办法很直接,系统没有,就自己装一个。
按y
同意。
安装好之后,输入R
试一下。
(Renv) [test@VM-0-7-centos ~]$ R
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
看一下library
的位置。
> .libPaths()
[1] "/home/test/anaconda3/envs/Renv/lib/R/library"
退出看看R
在哪。
(Renv) [test@VM-0-7-centos ~]$ which R
~/anaconda3/envs/Renv/bin/R
R
在Renv
的bin
文件夹中,当Renv
被激活时,直接输入R
进入,而当环境没有被激活时,可以直接绝对路径使用R
。
给R也配置一下镜像CRAN和Bioconductor
先来到R安装的位置。
(Renv) [test@VM-0-7-centos ~]$ cd /home/test/anaconda3/envs/Renv/lib/R/
(Renv) [test@VM-0-7-centos R]$ ls
bin COPYING doc etc include lib library modules share SVN-REVISION
可以看出这里和正常安装R
的安装目录结构差不多。
进入etc
文件夹后,新建一个Rprofile.site
文件(该文件为R
启动初期必须执行的文件)。
cd etc
vim Rprofile.site
<i>
输入以下内容,此处也可以提供非内置包的安装位置。
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")
保存。
<:>
<w>
<q>
<enter>
进入R
,看一下配置成功与否。
> options()$repos
CRAN
"https://mirrors.tuna.tsinghua.edu.cn/CRAN/"
这之后我们就可以愉快的安装包了。
install.packages('Seurat')
2 shell界面双R版本的切换 ,如果你conda有两个R版本,想来会切换怎么做?
比如:
#R3.6 /usr/bin/R R包有上面4个地方
#R4.0 /home/scR2021/miniconda3/bin/R
可以添加缩写以示区分:在/home/scR2021路径下搜索.bashrc文件,然后进入编辑,复制下面两句话添加到文件里面
alias R3='/usr/bin/R'
alias R4='/home/scR2021/miniconda3/bin/R'
保存退出,在conda中输入
scR2021@iZ0jlac7d4cxlrxfyzxkgoZ:~$ source ~/.bashrc
scR2021@iZ0jlac7d4cxlrxfyzxkgoZ:~$ R3
#R version 3.6.3 (2020-02-29)
scR2021@iZ0jlac7d4cxlrxfyzxkgoZ:~$ R4
#R version 4.0.3 (2020-10-10)
shell界面里面双R版本及包的安装路径配置完毕!!!根据需求调用不同的R版本。
参考: