I'm trying to write a script to install miniConda, then activate a conda environment.
Here's the relevant part of the code:
if ! command -v conda --version &> /dev/null
then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O conda.sh
bash conda.sh -b -p ~/local/miniconda3
rm -f conda.sh
~/local/miniconda3/bin/conda init bash
. ~/.bashrc
fi
conda config --set auto_activate_base false
conda create -yn my_env
eval "$(conda shell.bash hook)"
conda activate my_env
When I run the script, the output on my terminal looks as though conda was installed successfully. I get a long stream of messages, and, after reading through them all, it seems clear that everything was successful. (It's stuff like Solving environment: done
, if that helps).
However, when I run conda --version
at my terminal to test if I did install conda, I get the error conda: command not found
I can get conda --version
to work as expected if I follow this StackOverflow answer and type bash
into my terminal, then run conda --version
from there.
I've read a lot of answers about shells and subshells and how they relate to conda. I have the vague idea that my issue has to do with something (?) being executed in a subshell instead of the parent shell (?), and maybe something about sourcing ~/.bashrc
wrong (?). I need some major pointers on the details, though.
I apologize for not being able to form a better question. If I had a more specific idea of what to ask, I would just google it. :)
NOTE: Some of the stuff in my script (like ~/local/miniconda3/bin/conda init bash; . ~/.bashrc
) was copied from other StackOverflow answers. I read the explanations on those SO questions very carefully, but I unfortunately didn't come away with much more than the general idea "It works if you do this". It would be great if anyone answering could also explain if those lines relate to my question.