conda安装

确定系统及处理器

uname -a

我的是

Linux iZbp17za0hc4gx0mk0177zZ 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

可以安心下载 “Linux 64-bit”版本

我云主机空间有限,我选择Miniconda

创建专门放软件安装包的目录,用cd切换进去,用wget下载

mkdir -p $HOME/tools
cd $HOME/tools
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

校验SHA256 hash值,人工智能跟网站上的哈希码比较

openssl dgst -sha256 Miniconda3-latest-Linux-x86_64.sh

其实diff命令可以直接帮你判断的

思路就是:openssl得到的值,用awk取第2个字段,与网站上列的原来的值进行比较;因为diff命令后面原本跟的是文件,此处用<()运算直接用屏幕输出替代文件名。屏幕上若没有任何输出,则表示没有区别。

diff <(openssl dgst -sha256 Miniconda3-latest-Linux-x86_64.sh | awk '{print $2}') <(echo "4ee9c3aa53329cd7a63b49877c0babb49b19b7e5af29807b793a76bdb1d362b4")

关于Process Substitution(进程替换)的定义,可通过man bash进入bash帮助页再用/查找Process来查找

Process Substitution
   Process substitution allows a process's input or output to be referred to using a filename.   It  takes  the  form  of
   <(list)  or  >(list).   The  process  list is run asynchronously, and its input or output appears as a filename.  This
   filename is passed as an argument to the current command as the result of the expansion.  If the >(list) form is used,
   writing  to  the file will provide input for list.  If the <(list) form is used, the file passed as an argument should
   be read to obtain the output of list.  Process substitution is supported on systems that support named  pipes  (FIFOs)
   or the /dev/fd method of naming open files.

   When  available,  process substitution is performed simultaneously with parameter and variable expansion, command sub‐
   stitution, and arithmetic expansion.

head Miniconda3-latest-Linux-x86_64.sh 也可以看到这个文件的md5校验值 可以用md5sum Miniconda3-latest-Linux-x86_64.sh 来检验 👌

我的下载很完整,下面开始命令行安装miniconda

ll 可以看到这个文件没有可执行权限 那就加上解释器来安装

bash Miniconda3-latest-Linux-x86_64.sh 

安装过程,根据提示,可能依次要按回车、空格翻页读完licence(按空格翻页就行了,大家心里都知道自己有没有care过这些协议,咳咳)、输yes表示同意、输yes同意默认的安装路径(如果不同意,就输入自己想安装的绝对路径)、输yes让conda初始化。

安装过程手速别太快,别错过了让你输yes还是no的机会

重新登录即可生效。如果想在当前终端即可生效,可source ~/.bashrc(因为conda初始化的时候修改的是这个文件),然后输conda -h试试有没有安装成功呗,用conda list看看装了那些软件以及什么版本。

在base环境中安装R

从仓库里直接安装R(它的包名是r-base)

search一下(其实我个人更喜欢去anaconda仓库的conda-forge频道网页检索,可以直接搜到https://anaconda.org/conda-forge/r-base

只去默认的频道(main和r)搜了一下,都没有搜到conda-forge频道里搜到最新的R。

可能会提示conda update -n base -c defaults conda来更新一下conda。

conda install -c conda-forge r-base

悲哀,提示

error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory

允悲。其实在安装过程,但凡留意过屏幕,就会发现,安装的是好老好老的R版本,它依赖的是好老好老的readline。用find命令搜了一下,系统里的是.8,可以用ln -s做个符号链接,欺骗一下系统(ln -s简直是Linux大神,缺啥链啥)

ln -s ~/miniconda3/lib/libreadline.so ~/miniconda3/lib/libreadline.so.6

环境新建和使用

Q:我想装个新的R,但是又不想动原来的R,怎么办?

A:好办,把他们隔离开!各装各的!

Q:我就想装4.1版本,要怎么办啊?

A:问题不大,直接写版本号呗。

conda默认的环境是base,可以省略。

本来想演示conda search -c conda-forge 'r-base>=4'和conda install -c conda-forge r-base=4.1.2,但是小云要么死机,要么直接自动中止掉(需要的内存大于2G,在云主机上就别试了,在学校的大主机上可以试)

activate一个环境实际上就是把这个环境对应的bin的路径放到PATH变量的最前而已。

conda create -n r4
conda activate r4
# conda install -c conda-forge r-base=4.1.2
conda install -c r r-base=3.6.1
R --version
conda deactivate
R --version

加一个在内存更大的主机上测试conda search -c conda-forge 'r-base>=4'的截图吧(不禁感慨,离我准备前面内容才过去一个礼拜的样子,r又更新了,此刻它升到了4.1.3)