188

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
olivrg
  • 5,523
  • 3
  • 15
  • 19

27 Answers27

288

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,886
  • 1
  • 22
  • 36
olivrg
  • 5,523
  • 3
  • 15
  • 19
  • 36
    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
  • why isn't this already in my path? Why do I need to manually add it? :/ – Charlie Parker Nov 08 '22 at 23:29
  • After adding conda path to the $PATH inside .bashrc, and running `source .bashrc`; you may also need to run `conda init` – Zahra Feb 01 '23 at 18:51
  • It is enough to do `conda init zsh` to setup conda for Z shell. – passerby51 Apr 29 '23 at 17:53
94

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kenan
  • 13,156
  • 8
  • 43
  • 50
47

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

dew
  • 605
  • 5
  • 2
  • 4
    Can you explain what does this command actually do? Thanks! – Karan Sharma May 09 '21 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. – Hugo M. Zuleta May 14 '22 at 15:36
  • @Karan Sharma: The mysterious "[sourcing](https://en.wikipedia.org/wiki/Dot_(command)#Source)" explained – Peter Mortensen Apr 28 '23 at 16:35
34

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!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sanreet
  • 349
  • 3
  • 2
33

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xgMz
  • 3,334
  • 2
  • 30
  • 23
28

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
thrinadhn
  • 1,673
  • 22
  • 32
  • 2
    Don't forget to replace anaconda3 with miniconda3 if you're using miniconda. – Ari Sep 11 '22 at 12:04
  • This works only on current terminal – jonye._.jin Jan 31 '23 at 06:38
  • That is some completely messed up link! Can you [fix](https://stackoverflow.com/posts/64815977/edit) it? (But *** *** *** *** *** *** *** ***without*** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today) – Peter Mortensen Apr 28 '23 at 20:12
18

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

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

It worked for me.

Seth
  • 845
  • 8
  • 17
18

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bharath Kumar
  • 893
  • 9
  • 8
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.

CKE
  • 1,533
  • 19
  • 18
  • 29
Gursewak Singh
  • 172
  • 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RaphaëlR
  • 522
  • 7
  • 8
5

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"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Qazi Ammar
  • 953
  • 1
  • 8
  • 23
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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeevan
  • 8,532
  • 14
  • 49
  • 67
3

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

eval "$(/home/username/anaconda3/bin/conda shell.bash hook)"
Data Mastery
  • 1,555
  • 4
  • 18
  • 60
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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Taani
  • 71
  • 1
  • 3
2

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

2

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kiran beethoju
  • 141
  • 1
  • 4
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
  • 554
  • 6
  • 9
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".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mingming Qiu
  • 333
  • 4
  • 9
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Balint
  • 43
  • 6
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ali Akhtari
  • 1,211
  • 2
  • 21
  • 42
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Duarte Elvas
  • 123
  • 1
  • 8
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jobima
  • 5,790
  • 1
  • 20
  • 18
  • 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? – Peter Mortensen Apr 28 '23 at 20:10
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

Vladislav Povorozniuc
  • 2,149
  • 25
  • 26
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
  • 43
  • 1
  • 7
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Žygimantas
  • 302
  • 2
  • 13
-1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ryan Cocuzzo
  • 3,109
  • 7
  • 35
  • 64
-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.

Ajay Raut
  • 69
  • 1
  • 6