0

I am trying to create a Bash script that downloads a .sh file, runs it to install a program (Anaconda for Python), then run the command conda init to activate the default Anaconda environment base

However, running my bash script as shown

# !#/bin/bash
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
bash Anaconda3-*-Linux-x86_64.sh -b
echo 'export PATH=~/anaconda3/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
conda init
conda env create -f environment.yml

gives the error

./foo.sh: line 6: conda: command not found
./foo.sh: line 7: conda: command not found

Why is conda not found when trying to use it from within the Bash script, but is found if I relogin to the terminal?

How can we fix the Bash script so that using conda works?

Athena Wisdom
  • 6,101
  • 9
  • 36
  • 60
  • 2
    Change `~/` to `$HOME` instead. Also try using double quotes instead of single quotes. – Jetchisel Oct 01 '21 at 21:41
  • While this isn't a Docker build, I think the Dockerfiles for things like [Miniconda](https://hub.docker.com/r/continuumio/miniconda3/dockerfile) and [Miniforge](https://github.com/conda-forge/miniforge-images/blob/master/ubuntu/Dockerfile) are helpful references for good practices in how to bootstrap up a Conda installation. Also, I very much anti-recommend installing Anaconda - use a Miniforge or Miniconda installation. And you should not be adding `anaconda3/bin` to your PATH. – merv Oct 01 '21 at 22:28
  • @Jetchisel This works! Just noticed that problem in `bashrc` when not using double quotes – Athena Wisdom Oct 01 '21 at 22:56
  • Getting the warning message `IMPORTANT: You may need to close and restart your shell after running 'conda init'.` when the script tries to run `conda init` – Athena Wisdom Oct 01 '21 at 22:56
  • `conda init` configures a couple things for you, and modifies your `.bashrc`. So you need to logout and login to ensure all the modifications are applied. It is a warning, not an error. – Nic3500 Oct 06 '21 at 02:13

0 Answers0