Skip to content

Instantly share code, notes, and snippets.

@jph00
Last active April 23, 2026 12:20
Show Gist options
  • Select an option

  • Save jph00/3707260aeba1a9c03e469f5ecf524b34 to your computer and use it in GitHub Desktop.

Select an option

Save jph00/3707260aeba1a9c03e469f5ecf524b34 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
###
# NB: You probably don't want this gist any more.
# Instead, use this version from `fastsetup`:
# https://github.com/fastai/fastsetup/blob/master/setup-conda.sh
###
set -e
cd
case "$OSTYPE" in
darwin*) DOWNLOAD=https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh; RC_FILE=.bash_profile ;;
linux*) DOWNLOAD=https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; RC_FILE=.bashrc ;;
*) echo "unknown: $OSTYPE" ;;
esac
case "$SHELL" in
/bin/zsh*) SHELL_NAME=zsh; RC_FILE=.zshrc ;;
/bin/bash*) SHELL_NAME=bash ;;
/usr/local/bin/fish*) SHELL_NAME=fish ;;
*) echo "unknown: $SHELL" ;;
esac
cat << EOF > .condarc
channels:
- fastai
- pytorch
- defaults
channel_priority: strict
EOF
wget $DOWNLOAD
bash Miniconda3-latest*.sh -b
~/miniconda3/bin/conda init $SHELL_NAME
rm Miniconda3-latest*.sh
perl -n -e 'print if />>> conda/../<<< conda/' $RCFILE > .condainit
perl -ni -e 'print unless />>> conda/../<<< conda/' $RCFILE
echo source ~/.condainit >> $RCFILE
source ~/.condainit
@jph00

jph00 commented Aug 29, 2020 •

Copy link
Copy Markdown
Author

NB: You probably don't want this gist any more. Instead, use this version from fastsetup:

https://github.com/fastai/fastsetup/blob/master/setup-conda.sh

To install fastai, once you've run this, run:

conda install fastai

NB: If you've installed Anaconda or miniconda before, and you want to start with a fresh install, remove (or rename) your existing ~/anaconda3 or ~/miniconda3 directory before you run this script.

@aseifert

aseifert commented Aug 29, 2020 •

Copy link
Copy Markdown

I'm using fish shell (on mac) which is unfortunately not compatible with bash syntax, so instead of sourcing it, you need to start the setup with: bash setup_conda.sh. Then you will want to add the following line to the $SHELL case switch: /usr/local/bin/fish*) SHELL_NAME=fish ;; (for me fish is at /usr/local/bin/fish, check your location by running echo $SHELL). This ensures that later the conda init line will be invoked with fish as last param.

The .bashrc lines are not doing any harm on a fish system (don't have a .bashrc so .condainit will be empty and sourcing it will do nothing)

Finally I had to change the last line to conda install mamba -c conda-forge (as specified in mamba's installation guide), should not be a fish specific thing though as far as i can tell? Without specyfing conda-forge as a channel that installation failed on my machine.

And when you say "to install fastai with mamba…run" you are I think forgetting to tell users to alias conda to mamba (i know you did on twitter, but people might not have seen that coming here).

@johnp-4dvanalytics

Copy link
Copy Markdown

Thanks for sharing Jeremy! I had an error "setup_conda.sh: line 34: source: .condainit: file not found." My OS is Centos 7. I was able to fix the issue by switching the command to "source ~/.condainit"

@EtienneT

EtienneT commented Sep 1, 2020

Copy link
Copy Markdown

Just a quick note for anyone using Ubuntu in WSL2, don't delete your ~/anaconda3 folder if you want to start fresh. Everything is broken now :(.

@jtbr

jtbr commented Jan 24, 2021 •

Copy link
Copy Markdown

It seems like a great idea for managing environments. But the script seems not to be working anymore. After the miniconda install (seemingly after running the condainit script it creates), it stops, saying:
==> For changes to take effect, close and re-open your current shell. <==
Also, if I then try to run conda install -y mamba it appears not to find it in the provided channels (the current documentation recommends conda-forge?)

@CalvHobbes

Copy link
Copy Markdown

Leaving this here just in case: I finally added the channel manually: conda config --append channels conda-forge, after which I was able to run
conda install -y mamba

@jph00

jph00 commented Feb 3, 2024

Copy link
Copy Markdown
Author

mamba is no longer needed -- I've now updated the gist to reflect that. I've also added a link to a somewhat more official version that's in fastsetup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment