Linux 下安装miniconda

Miniconda 和 Conda 都是用于管理 Python(及其他语言)环境和包的工具。

conda对于我来说是太臃肿了,很多的包我不会使用,所以选择安装miniconda是一个较好的选择。

下面是linux安装miniconda的实际操作。

在以下的网站,选择你要安装的Miniconda的版本。

https://docs.conda.io/en/latest/miniconda.html#linux-installers

image-20240820174737486

1、下载安装包Miniconda3-latest-Linux-x86_64.sh

2、把安装包上传到服务器上,这里放在 /home/software

3、安装

bash Miniconda3-latest-Linux-x86_64.sh

4、按回车

image-20240820175434688

5、按空格跳到最下面,输入yes

image-20240820175516660

6、选择安装位置,这里选择默认,直接回车,有需要可以自己输入改掉

Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>> 
PREFIX=/root/miniconda3

7、初始化 miniconda,输入 yes

installation finished. Do you wish the installer to initialize Miniconda3 by running conda init? [yes|no] [no] >>> yes

8、现在 conda 命令是找不到的,需要激活

source ~/.bashrc

激活后可以看到启动了 base 环境,conda 命令也可以用了,下一节会介绍常用 conda 命令。

9、可以设置启动时,不自动激活 base 环境

conda config --set auto_activate_base false

10、设置 conda 镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

11、设置 pip 镜像

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

12、查看 python 环境

(base) root@aa:/home/software# python
Python 3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 15:12:24) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello,rs')
hello,rs
>>> exit()

可以看到默认的 python 环境是 3.12,也就是我们安装的 miniconda 的 python 版本。