135

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 zsh by the way.

Thrastylon
  • 677
  • 3
  • 18
olivrg
  • 4,293
  • 3
  • 13
  • 19
  • 3
    Did you try with full path `/home/username/miniconda3/bin/conda`? – Mike Müller Feb 06 '16 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 06 '16 at 21:02
  • I've tried the full path /home/username/miniconda3/bin/conda. Unfortunately, it didn't work. – olivrg Feb 06 '16 at 21:13
  • @dhke It is set up to read .bashrc. I have no issue with RVM – olivrg Feb 06 '16 at 21:17
  • @olivrg Nevermind then. Did the full path invocation return an error message? – dhke Feb 06 '16 at 21:19
  • It didn't return any errors. – olivrg Feb 06 '16 at 21:20
  • @dhke you were right. I wasn't set up to read the .bashrc. It's working now after adding the environment variable to .zshrc as you suggested. Cheers mate! – olivrg Feb 06 '16 at 21:25
  • Does this answer your question? [How to run Conda?](https://stackoverflow.com/questions/18675907/how-to-run-conda) – merv Apr 05 '21 at 12:38

21 Answers21

222

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.

Gabriel Florit
  • 2,884
  • 1
  • 21
  • 37
olivrg
  • 4,293
  • 3
  • 13
  • 19
  • 31
    Instead of exiting and reopening, Using `source ~/.zshrc` will do – dlmeetei Feb 06 '16 at 22:12
  • I tried this, but I still get an error when trying to install stuff `CondaIOError: Missing write permissions in: /anaconda` – Thomas Ahle Nov 13 '17 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 – Johnny Jan 13 '18 at 14:56
  • 1
    For those who don't know: copy the command in the `.zshrc` file that will be located in your `/User//` directory. – bpz Oct 19 '20 at 12:36
  • My binary was in condabin at in /usr/local/anaconda3--it's 2021 and I'm on a Mac. I added condabin to the path in .zshrc at /User// and it worked. – maria Jan 21 '21 at 19:11
  • ```nano ~/.bashrc``` - then in the end add ```export PATH="/home/username/miniconda3/bin:$PATH"``` Make check if its miniconda or miniconda3 ```source ~./.bashrc``` – Vinay Verma Sep 18 '21 at 10:01
  • where is `.zshrc`? Is it a mac thing? – Gulzar Feb 14 '22 at 09:56
  • `.zshrc` is the configuration file. You can open it with your text editor using this command: `nano ~/.zshrc` – olivrg Feb 16 '22 at 09:45
75

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

Derek O
  • 11,124
  • 3
  • 19
  • 35
Kenan
  • 11,783
  • 8
  • 39
  • 49
28

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

dew
  • 415
  • 4
  • 2
  • 2
    Can you explain what does this command actually do? Thanks! – Karan Sharma May 09 '21 at 20:16
  • @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. – Hugo M. Zuleta May 14 '22 at 15:36
27

For those experiencing issues after upgrading to MacOS 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 - reintall anaconda - 
# brew cask install anaconda

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

Further reading - Anaconda blog post and Github discussion.

xgMz
  • 3,149
  • 2
  • 28
  • 21
23

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

Close your terminal window and restart it.

It worked for me now!

Sanreet
  • 239
  • 2
  • 2
  • 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 07 '21 at 20:56
16

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

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

It worked for me.

Seth
  • 795
  • 7
  • 16
  • 3
    On ubuntu i needed to refer to home so i used: `export PATH="~/anaconda3/bin":$PATH` and it worked – Oha Noch Mar 21 '21 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 07 '21 at 21:06
13

To initialize your shell run the below code

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

It's 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

thrinadhn
  • 956
  • 9
  • 28
8

conda :command not found

Try adding below line to your .bashrc file

export PATH=~/anaconda3/bin:$PATH

then try:

conda --version

to see version

and then to take affect

conda init 
Bharath Kumar
  • 492
  • 6
  • 7
7

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.

CKE
  • 1,435
  • 15
  • 19
  • 28
Gursewak Singh
  • 162
  • 1
  • 6
5

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.

sɐunıɔןɐqɐp
  • 2,877
  • 15
  • 33
  • 38
Golddy
  • 472
  • 6
  • 8
4

I faced this issue on my mac after updating conda. Solution was to run conda mini installer on top of 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: https://github.com/conda/conda/issues/1364

Homero Esmeraldo
  • 1,484
  • 1
  • 14
  • 31
Jeevan
  • 8,132
  • 12
  • 47
  • 65
2

Make sure that you are installing the Anaconda binary that is compatible with your kernel. I was in the same situation.Turned out I have an x64_86 CPU and was trying to install a 64 bit Power 8 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 2 different types of 64-Bit installers -

  • 64-Bit (x86) installer and
  • 64-Bit (Power 8) installer.
Taani
  • 71
  • 3
1

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

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

Echo9k
  • 348
  • 3
  • 8
1

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

eval "$(/home/username/anaconda3/bin/conda shell.bash hook)"
Data Mastery
  • 989
  • 3
  • 11
  • 31
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".

Mingming Qiu
  • 196
  • 1
  • 4
1

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

Balint
  • 43
  • 6
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.

jobima
  • 5,662
  • 1
  • 19
  • 18
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

frmbelz
  • 1,537
  • 16
  • 22
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.

k-krakowski
  • 33
  • 1
  • 7
-1

MacOSX: cd /Users/USER_NAME/anaconda3/bin && ./activate

Ryan Cocuzzo
  • 2,829
  • 5
  • 32
  • 53