A while ago, we discussed about Anaconda Python distribution, and how to install and use Anaconda on Linux. Today, we will look at what is Miniconda, how to install miniconda in Linux.
Table of Contents
What is Miniconda?
Miniconda is a minimal and stripped-down version of Anaconda distribution. As the name implies, Miniconda contains only Conda package manager, Python and a small number of useful packages such as pip, zlib including their dependencies.
Miniconda is suitable for those who don't mind to install each package individually. It saves you not only the disk space but also avoids dumping a lots of unnecessary applications that you don't use often in your hard drive. For those wondering, Anaconda distribution automatically installs 1,500 packages that consumes around 3 GB disk space. If you use only a handful of applications, miniconda might be a good choice!
Install Miniconda in Linux
Download the latest Miniconda version from the official download page.
$ wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
Go to the location where you downloaded the Miniconda installer and check the integrity of the downloaded file with SHA-256:
$ sha256sum Miniconda3-py39_4.9.2-Linux-x86_64.sh
You will see an output like below:
536817d1b14cb1ada88900f5be51ce0a5e042bae178b5550e62f61e223deae7c Miniconda3-py39_4.9.2-Linux-x86_64.sh
Compare the above hash value with the official Hashes for Miniconda. If the hash value of the locally downloaded installer file matches with the official hash, it is a legitimate file and you can start the installation!
To install Miniconda on Linux, run:
$ bash Miniconda3-py39_4.9.2-Linux-x86_64.sh
You should include the bash command regardless of the shell you're using.
Press ENTER to continue installation:
Welcome to Miniconda3 py39_4.9.2 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue
Next, you will see the license agreement. Press ENTER key to scroll to the bottom of the license terms and type “Yes” and press to agree the license agreement and continue installation.
Do you accept the license terms? [yes|no]
[no] >>> yes
Next the installer will prompt where do you want to install Miniconda. You will be given three choices. Press ENTER to accept the default install location i.e. your $HOME
directory. If you don't want to install in the default location, press CTRL+C to cancel the installation or mention an alternate installation directory.
I go with the default installation path, which is /var/home/sk/miniconda3
in my case.
[...] Miniconda3 will now be installed into this location: /var/home/sk/miniconda3 Press ENTER to confirm the location Press CTRL-C to abort the installation Or specify a different location below [/var/home/sk/miniconda3] >>>
If you've chosen the default location, the installer will display “PREFIX=/var/home/<user>/miniconda3”
and continue the installation. It may take a few minutes to complete.
Finally, you will be prompted to initialize Miniconda. It is recommended to initialize it, so just type Yes and press ENTER to continue.
[...] Preparing transaction: done Executing transaction: done installation finished. Do you wish the installer to initialize Miniconda3 by running conda init? [yes|no] [no] >>> yes
Once the Miniconda installation is completed, you will see a thank you note at the end.
[...] ==> For changes to take effect, close and re-open your current shell. <== 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 Miniconda3!
For the installation to take effect, close and re-open your Terminal. Alternatively, run the following command to effect the changes immediately:
$ source ~/.bashrc
You will now see the prefix (base) in front of your shell prompt. It means that the conda's base environment is activated.
(base) [sk@ostechnix-silverblue ~]$
If you don't want the conda's base environment activated by default on system startup and wish to run conda from anywhere, deactivate it using command:
$ conda config --set auto_activate_base false
Run the following command to take effect the changes immediately:
$ source ~/.bashrc
From now on, you have to manually activate conda environment using command:
$ conda activate
To deactivate conda environment:
$ conda deactivate
Miniconda unattended installation
Miniconda installer script comes with options to perform unattended installation. It doesn't require any manual intervention from the user.
First, create a directory for Miniconda installation:
$ mkdir ~/miniconda
Download the installer script:
$ wget https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh
Verify the checksum as shown above. And then run the following command to install Miniconda in silent mode:
$ bash Miniconda3-py39_4.9.2-Linux-x86_64.sh -b -u -p ~/miniconda3
Here, -b
flag is used to run the installation in batch mode. Meaning - the license agreement will automatically accepted. The -u
flag is update the existing installation if Miniconda is already installed. And the -p
flag is used to specify the destination directory where you want to install Miniconda. In our case, I have chosen ~/miniconda
directory.
After the installation is completed, the installer will ask whether you want to initialize conda. Type Yes
to agree and complete the installation.
Update Miniconda
Runthe following command from you r Terminal to update Miniconda:
$ conda update conda
Uninstall Miniconda
If you don't require conda anymore, simply remove the Miniconda install directory:
$ rm -fr ~/miniconda3
Some hidden files and folders that may have been created in the $HOME directory. Delete them as well:
$ rm -rf ~/.condarc ~/.conda ~/.continuum
Finally edit ~/.bashrc
file:
$ nano ~/.bashrc
Find and delete the whole block that starts with >>>conda initialize>>>
and ends with <<<conda intialize<<<
.
>>> conda initialize >>> !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/var/home/sk/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/var/home/sk/miniconda3/etc/profile.d/conda.sh" ]; then . "/var/home/sk/miniconda3/etc/profile.d/conda.sh" else export PATH="/var/home/sk/miniconda3/bin:$PATH" fi fi unset __conda_setup <<< conda initialize <<<
Press Ctrl+O
followed by Ctrl+X
to save the file and close it. Source the ~/.bashrc
file to take effect the changes:
$ source ~/.bashrc
That's it. Miniconda has been removed from the system.