AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

CondaError: Run 'conda init' Before 'conda activate' — Fix (2026)

By Luca Berton · Published 2024-01-01 · Category: installation

Fix CondaError: Run 'conda init' before 'conda activate' in bash, zsh, fish, PowerShell, Docker, and CI/CD. Step-by-step solution for every shell and OS.

Introduction

If you're working in data science, machine learning, or any field involving Python programming, you might be familiar with Conda – a powerful package and environment management system. However, a common hurdle that many users face is an error when trying to activate a Conda environment: "conda error: run 'conda init' before 'conda activate'". This message indicates that Conda hasn't been properly initialized in your shell environment, but don't worry – it's a fixable issue!

Why Does This Error Occur

Conda environments need to be activated to switch between different Python versions or sets of packages. The conda activate command is essential for this, but it requires Conda to be initialized in your shell. Without initialization, your shell can't recognize the conda activate command, leading to the error.

How to Fix It Initialize Conda for Your Shell: Run conda init. This command modifies your shell's startup file (like .bashrc for Bash, .zshrc for Zsh), integrating Conda into your shell environment. This is a one-time setup – once done, you won't need to repeat it for future sessions. Temporary Solution with eval "$(conda shell.bash hook)": If, for some reason, you prefer not to run conda init, there's a workaround. Use eval "$(conda shell.bash hook)". It's a temporary measure that initializes Conda for the current shell session without altering the startup file. Remember, this is a session-specific solution and needs to be repeated each time you open a new shell.

Example Usage

Keep in Mind • Post conda init, a shell restart might be necessary for the changes to take effect. • eval "$(conda shell.bash hook)" offers a temporary fix and must be executed in every new shell session if conda init is not an option.

The Error

Fix for Bash

Fix for Zsh

Fix for Fish

What conda init Does

Adds a block to your shell RC file:

Alternative: Source Directly

Fix in Scripts

Fix in Ansible

Fix in Docker

Fix in CI/CD (GitHub Actions)

Disable Auto-Activation

Troubleshooting

conda command not found

Wrong Python after activation

FAQ

Why did this start happening?

Conda 4.4+ changed activation to use conda activate instead of source activate. The new method requires shell initialization.

Can I use the old source activate?

It's deprecated but may still work. Use conda activate after running conda init.

Does this affect Jupyter notebooks?

Only if launching from terminal. Jupyter kernels have their own Python path configured separately via ipykernel.

The Error

Quick Fix

What conda init Does

It adds initialization code to your shell profile:

Alternative: Manual Activation

Fix for Different Shells

Bash

Zsh

Fish

PowerShell

Fix in Docker/CI

Fix in Ansible

Fix in Cron Jobs

Disable Auto-Activation

Common Issues

| Problem | Solution | |---------|----------| | conda activate doesn't work | Run conda init | | Wrong Python after activate | Check which python inside env | | base activates every time | conda config --set auto_activate_base false | | conda not found | Add conda to PATH: export PATH="/opt/conda/bin:$PATH" | | Permission denied | Don't use sudo conda — install in user space | | SSH session conda fails | Source conda.sh in ~/.bashrc or ~/.profile |

Uninstall conda init Changes

FAQ

Why can't I just use source activate?

source activate is the old (deprecated) way. conda activate is the modern approach but requires shell initialization via conda init.

Does this affect pip/virtualenv?

No — this is specific to Conda environments. pip and virtualenv work independently.

Miniconda vs Anaconda — same fix?

Yes — both use the same conda command and conda init process.

The Error

Quick Fix

Fix for Scripts

Fix for Docker

Fix for CI/CD

Fix with Ansible

Alternative: Use conda run

Conda Not Found

Multiple Shell Support

FAQ

Why does this happen?

conda activate requires shell hooks installed by conda init. Without them, conda can't modify the shell environment to switch environments.

conda activate vs source activate?

conda activate is the modern way (requires conda init). source activate is legacy and may be removed. Use conda activate.

How to undo conda init?

Conclusion By following these steps, you should be able to seamlessly activate your Conda environments, paving the way for a smoother workflow in your Python projects. Remember, proper environment management is key in Python programming, especially when juggling multiple projects with varying dependencies. Happy coding! 🐍💻

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home