conda-init
Initialize Conda for shell
TLDR
Initialize a specific shell (if none is specified, defaults to bash for UNIX and powershell for Windows)
Initialize all available shells
Initialize conda for all users on the system
Don't initialize conda for the current user
Add condabin/ directory to PATH
Undo effects of the last conda init
SYNOPSIS
conda-init [OPTIONS] SHELL
PARAMETERS
SHELL
(required) The type of shell to initialize Conda for (e.g., bash, zsh, fish, powershell).
-h, --help
Displays a help message and exits.
--version
Shows the program's version number and exits.
-d, --debug
Enables debug messages for troubleshooting.
-q, --quiet
Suppresses progress indicators and non-essential output.
-v, --verbose
Produces more detailed output.
--no-prefix
Prevents the setting of CONDA_PREFIX and other prefix-related variables.
--no-stack
Disables the ability to stack Conda environments (default is stacking enabled).
--stack
Explicitly enables environment stacking (this is the default behavior).
--activate
Activates the base Conda environment upon initialization (this is the default behavior).
--no-activate
Prevents the automatic activation of the base environment.
--unset-vars
Unsets environment variables from previous Conda environment activations.
--no-unset-vars
Retains environment variables from previous activations (this is the default behavior).
DESCRIPTION
The conda-init command is a specialized utility designed to prepare a shell environment for Conda usage in non-interactive contexts, such as scripts, CI/CD pipelines, Dockerfiles, or system services. Unlike conda init, which modifies your shell's startup files (like .bashrc or .zshrc) for persistent interactive use, conda-init generates and outputs the necessary shell code to initialize Conda for the current shell session only.
This ensures that Conda commands like conda activate, conda install, and conda run function correctly without permanently altering the shell configuration of the user or system. It achieves this by setting up the PATH variable and defining essential shell functions required for Conda's environment management capabilities. This makes it ideal for environments where a clean, reproducible, and non-persistent setup is crucial.
CAVEATS
1. Non-Persistent: conda-init only initializes Conda for the current shell session. Its effects are not persistent across new shell instances.
2. Non-Interactive Use: Primarily designed for use in scripts, Dockerfiles, or CI/CD pipelines where user interaction is not expected.
3. Requires Sourcing/Eval: The output of conda-init must be sourced (e.g., eval "$(conda-init bash)") into the current shell to take effect.
4. CONDA_EXE or CONDA_ROOT: For proper operation, either the conda executable must be in the system PATH, or the CONDA_EXE or CONDA_ROOT environment variables must be correctly set before running conda-init.
USAGE EXAMPLE:
To initialize Conda in a bash script, you would typically use eval to execute the output of conda-init:eval "$(conda-init bash)"
After this, you can safely use commands like conda activate myenv, conda install, etc., within the same script.
ENVIRONMENT VARIABLES:
conda-init relies on the PATH variable to find the conda executable. If conda is not in PATH, you might need to set CONDA_EXE to the full path of your conda executable or CONDA_ROOT to the root of your Conda installation before running conda-init.
Example:export CONDA_EXE="/path/to/miniconda3/bin/conda"eval "$(conda-init bash)"
HISTORY
The conda-init command emerged as a crucial component within the Conda ecosystem to address the growing need for robust and reliable Conda usage in automated and non-interactive environments. Prior to its introduction, users often resorted to manual sourcing of internal Conda scripts (like _conda_activate_setup.sh) or complex workarounds to make Conda function correctly outside of interactive login shells. This was often brittle and subject to changes in Conda's internal structure. conda-init standardizes this process, providing a stable, officially supported interface for integrating Conda into scripts, Docker images, and CI/CD systems, significantly improving the developer experience for automation and reproducibility.
SEE ALSO
conda(1): The main Conda command-line interface for package, environment, and channel management., source(1) or .(1): Shell built-ins used to execute commands from a file in the current shell context, essential for applying conda-init output., bash(1), zsh(1), fish(1): Common shells that conda-init supports for initialization.


