205

I've installed Miniconda and have added the environment variable export PATH="/home/username/miniconda3/bin:$PATH" to my .bashrc and .bash_profile, but still can't run any Conda commands in my terminal.

Am I missing another step in my setup? I'm using Z shell (executable zsh) by the way.

9
  • 4
    Did you try with full path /home/username/miniconda3/bin/conda? Feb 6, 2016 at 21:01
  • 3
    And your zsh is set up to read .bashrc (I doubt it, it's called ._bash_rc for a reason)? By default zsh reads .zprofile and .zshrc, instead (plus .zlogin for login shells).
    – dhke
    Feb 6, 2016 at 21:02
  • I've tried the full path /home/username/miniconda3/bin/conda. Unfortunately, it didn't work.
    – olivrg
    Feb 6, 2016 at 21:13
  • @dhke It is set up to read .bashrc. I have no issue with RVM
    – olivrg
    Feb 6, 2016 at 21:17
  • 1
    why isn't this already in my path? Why do I need to manually add it? :/ Nov 8, 2022 at 23:29

28 Answers 28

314

If you're using zsh and it has not been set up to read .bashrc, you need to add the Miniconda directory to the zsh shell PATH environment variable. Add this to your .zshrc:

export PATH="/home/username/miniconda/bin:$PATH"

Make sure to replace /home/username/miniconda with your actual path.

Save, exit the terminal and then reopen the terminal. conda command should work.

11
  • 38
    Instead of exiting and reopening, Using source ~/.zshrc will do
    – dlmeetei
    Feb 6, 2016 at 22:12
  • 1
    I tried this, but I still get an error when trying to install stuff CondaIOError: Missing write permissions in: /anaconda Nov 13, 2017 at 13:38
  • 1
    It works! But the path has a slight difference. export PATH="/Users/victorzhang/anaconda2/bin:$PATH", the path beginning is /Users/, instead of /home/ still thank you @olivrg
    – M.Bonjour
    Jan 13, 2018 at 14:56
  • 1
    For those who don't know: copy the command in the .zshrc file that will be located in your /User/<yourusername>/ directory.
    – bpz
    Oct 19, 2020 at 12:36
  • 1
    nano ~/.bashrc - then in the end add export PATH="/home/username/miniconda3/bin:$PATH" Make check if its miniconda or miniconda3 source ~./.bashrc Sep 18, 2021 at 10:01
99

If you have the PATH in your .bashrc file and are still getting

conda: command not found

Your terminal might not be looking for the Bash file.

Type bash in the terminal to ensure you are in Bash and then try:

conda --version

6
  • 2
    thanks for this! But what is the reason we have to type bash?
    – patti_jane
    Dec 18, 2019 at 16:00
  • 1
    im not 100% sure but I think it's to let your command prompt read the bashrc file
    – Kenan
    Dec 18, 2019 at 16:36
  • 2
    Yes, the start script for conda was added inside your .bashrc file during installation, so you need to start bash shell to start the conda Jan 12, 2021 at 0:55
  • why isn't this already in my path? Why do I need to manually add it? :/ Nov 8, 2022 at 23:29
  • when you installed conda you might have select NO to add to path since it's the default.
    – Kenan
    Nov 9, 2022 at 18:35
53

Maybe you need to execute "source ~/.bashrc"

3
  • 4
    Can you explain what does this command actually do? Thanks! May 9, 2021 at 20:16
  • 1
    @KaranSharma I believe it resets the environment variables for your profile. If you recently installed Anaconda, that file was edited by the installer with the new env variables, but have not been loaded for conda or other utilities. I might be wrong, I'm new to this whole thing. May 14, 2022 at 15:36
  • 1
    @Karan Sharma: The mysterious "sourcing" explained Apr 28, 2023 at 16:35
42

To initialize your shell, run the below code:

source ~/anaconda3/etc/profile.d/conda.sh
conda activate Your_env

It worked for me. I got the solution from the below link
https://www.codegrepper.com/code-[“CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.][1]examples/shell/CommandNotFoundError%3A+Your+shell+has+not+been+properly+configured+to+use+%27conda+activate%27.+To+initialize+your+shell%2C+run

3
  • 2
    Don't forget to replace anaconda3 with miniconda3 if you're using miniconda.
    – Ari
    Sep 11, 2022 at 12:04
  • This works only on current terminal Jan 31, 2023 at 6:38
  • That is some completely messed up link! Can you fix it? (But *** *** *** *** *** *** *** without *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today) Apr 28, 2023 at 20:12
40

Sometimes, if you don't restart your terminal after you have also installed Anaconda, it gives this error.

Close your terminal window and restart it.

It worked for me now!

1
  • Also instead of close/open terminal, could source ~/.bashrc OR . ~/.barshrc if bash is a shell you are using (to see your shell echo $0)
    – frmbelz
    Dec 7, 2021 at 20:56
34

For those experiencing issues after upgrading to macOS v10.15 (Catalina).

Short version:

# 1a) Use tool: conda-prefix-replacement -
# Restores: Desktop -> Relocated Items -> Security -> anaconda3
curl -L https://repo.anaconda.com/pkgs/misc/cpr-exec/cpr-0.1.1-osx-64.exe -o cpr && chmod +x cpr
./cpr rehome ~/anaconda3
# or if fails
#./cpr rehome ~/anaconda3 --old-prefix /Anaconda3
source ~/anaconda3/bin/activate

# 1b) Alternatively - reinstall Anaconda -
# brew cask install anaconda

# 2) conda init
conda init zsh
# or
# conda init

Further reading - Anaconda blog post and GitHub discussion.

21

conda: command not found

Try adding the below line to your .bashrc file:

export PATH=~/anaconda3/bin:$PATH

Then try:

conda --version

to see the version.

And then for it to take effect

conda init
18

Maybe you should type add this to your .bashrc or .zshrc

export PATH="/anaconda3/bin":$PATH

It worked for me.

2
  • 4
    On ubuntu i needed to refer to home so i used: export PATH="~/anaconda3/bin":$PATH and it worked
    – Oha Noch
    Mar 21, 2021 at 12:25
  • echo $0 to see what shell if it is .bashrc or .zshrc OR ls -ld ~/.* to see which one is already there.
    – frmbelz
    Dec 7, 2021 at 21:06
9

If you are using Mac and have installed Conda with Homebrew then you need to run this command to export the path:

export PATH="$PATH:/opt/homebrew/anaconda3/bin"
8

Execute the following command after installing and adding to the path

source ~/.bashrc

where source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell.

It runs during boot up automatically.

6

I had the same issue. I just closed and reopened the terminal, and it worked. That was because I installed Anaconda with the terminal open.

4

I faced this issue on my Mac after updating Conda. The solution was to run the Conda mini installer on top of the existing Conda setup.

curl https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o ~/miniconda3.sh
bash ~/miniconda3.sh -bfp ~/miniconda3

On Linux, you can use:

curl https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -o ~/miniconda3.sh
bash ~/miniconda3.sh -bfp ~/miniconda3

For other versions, you can go to https://repo.continuum.io/miniconda/

For details, check: Conda command not found after running conda update package #1364

0
3

I had to run the following command to activate the shell:

eval "$(/home/username/anaconda3/bin/conda shell.bash hook)"
3

If you are using Linux:

After installing Anaconda from the .sh file (which you can download from https://www.spyder-ide.org/):

Step 1: Activate the environment in the terminal by entering the below command.

source ~/anaconda3/bin/activate

Step 2:

Type spyder in the terminal. You can get the Spyder IDE.

spyder
2

export PATH="~/anaconda3/bin":$PATH

1
  • That is a bit terse. In what context? Where should it be applied? Apr 28, 2023 at 20:25
2

Make sure that you are installing the Anaconda binary that is compatible with your kernel.

I was in the same situation. It turned out I have an x64_86 CPU and was trying to install a 64-bit POWER8 installer. You can find out the same for your CPU by using the following command. It gives you a basic information about a computer's software and hardware.

uname -a

https://www.anaconda.com/download/#linux

The page in the link above displays two different types of 64-bit installers:

  • 64-bit (x86) installer and
  • 64-bit (POWER8) installer.
1

The brute-force way could be

if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/root/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/root/miniconda3/bin:$PATH"
    fi
fi

Then initialize and test Conda.

conda init
conda -V

Which is what Conda tries to do. Take a look at the end of ~/.bashrc with less ~/.bashrc or with cat ~/.bashrc

1

Do the same thing as the suggestion given by bash console, but pay attention that there are some errors in the suggestion (the file path format is incorrect). Paste these two commands in the Bash console for Windows:

echo ". C:/Users/mingm/Anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc

and

echo "conda activate" >> ~/.bashrc

After having pasted these two commands, exit the Bash console, reload it and then activate the virtual environment by entering "conda activate your_env_name".

1

It can be a silly mistake. Make sure that you use anaconda3 instead of anaconda in the export path if you installed it so.

1

By default, Anaconda and Miniconda will put necessary command alias to the .bashrc file file.

All you have to do is to reload added alias inside ~/.bashrc using this command:

source ~/.bashrc
1
  • 1
    This works. Alternatively, if you are using zsh, you need to source ~/.zshrc
    – Talita
    Jan 31, 2023 at 8:20
1

I am using a WSL system.

In my case, for the conda command to be added to the path, and persist, I had to do the following:

First:

vim ~/.bashrc

This will open the .bashrc file using Vim. You should go to the bottom of the file using the arrow keys, click i to toggle the insert mode and paste: export PATH="$PATH:/home/userName/miniconda3/bin".

After that, save and close Vim using :wq.

(if you are not comfortable using Vim, you can use the nano command instead)

nano ~/.bashrc

Second:

source ~/.bashrc

Third:

Close and open the terminal! This should work for everyone.

To test if it is working, try:

conda --version
0

This worked for me on CentOS and miniconda3. Find out which shell you are using

echo $0

conda init bash (could be conda init zsh if you are using zsh, etc.) - this adds a path to ~/.bashrc

Reload command line

sourc ~/.bashrc OR . ~/.bashrc

0

I have encountered this problem lately and I have found a solution that worked for me. It is possible that your current user might not have permissions to anaconda directory, so check if you can read/write there, and if not, then change the files owner by using chown.

0

For Conda > 4.4 follow this:

echo ". /home/ubuntu/miniconda2/etc/profile.d/conda.sh" >> ~/.bashrc

Then you need to reload user bash, so you need to log out:

exit

And then log again.

1
  • What do you mean by "reload user bash"? Reload the content of file .bashrc? Or something to do with file /usr/bash? Or something else? Apr 28, 2023 at 20:10
0

This worked on an M1 Mac:

To get the user name:

echo $USER

Then substitute my_username with the correct one.

source /Users/my_username/opt/anaconda3/bin/activate
0

For me uninstalling and reinstalling miniconda did the trick. I did lose all my existing repos but at least the command works now.

-1

Mac OS X: cd /Users/USER_NAME/anaconda3/bin && ./activate

-1

To add Anaconda to your system's PATH as well as User PATH on Windows, you can follow these steps:

  1. Find Anaconda Installation Directory: The Anaconda installation directory will typically be something like C:\Users\<YourUsername>\Anaconda3 or C:\ProgramData\Anaconda3, depending on whether it's installed for a specific user or for all users.

  2. Open System Properties:

    • Right-click on the Start button and select System.
    • Click on Advanced system settings on the left-hand side.
  3. Environment Variables:

    • In the System Properties window, click the Environment Variables button at the bottom.
  4. Edit System Variables:

    • Under the "System Variables" section, find the Path variable and select it.
    • Click the Edit button.
  5. Add Anaconda Path:

    • Click the New button and add the path to the Anaconda installation directory. For example: C:\Users\<YourUsername>\Anaconda3 or C:\ProgramData\Anaconda3.
  6. Save and Apply Changes:

    • After adding the Anaconda path, click OK to close each of the open windows.

    • Repeat step 4,5 and 6 for adding the path to User PATH as well

  7. Restart Command Prompt:

    • If you have a Command Prompt or PowerShell open, close and reopen it for the changes to take effect.
  8. Verify Installation:

    • Open a new Command Prompt or PowerShell window.
    • Type conda --version and press Enter. This should display the version of Conda if the PATH configuration was successful.

Remember to replace <YourUsername> with your actual Windows username and adjust the installation path if you installed Anaconda in a different location.

Not the answer you're looking for? Browse other questions tagged or ask your own question.