Home > OS >  Safest method to clean up my .bash_profile on MacOS?
Safest method to clean up my .bash_profile on MacOS?

Time:02-20

I'm new to the Mac environment and installed the Anaconda GUI by accident. I wished to remove it completely and install Miniconda instead. I think I was successful, except the only remnant I can find of Anaconda is in my .bash_profile. It looks something like:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/connor/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/connor/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/connor/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/connor/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

Is .bash_profile something included with my system by default? How should I revert all of the changes Anaconda made to my file or would I be safe to just delete it entirely?

Note: I do not have Miniconda installed yet and am waiting to completely remove all traces of Anaconda first.

Edit: Additionally, I have found more artifacts in .xonshrc and .zshrc. They show, respectively:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
import sys as _sys
from types import ModuleType as _ModuleType
_mod = _ModuleType("xontrib.conda",
                   "Autogenerated from $(/Users/connor/opt/anaconda3/bin/conda shell.xonsh hook)")
__xonsh__.execer.exec($("/Users/connor/opt/anaconda3/bin/conda" "shell.xonsh" "hook"),
                      glbs=_mod.__dict__,
                      filename="$(/Users/connor/opt/anaconda3/bin/conda shell.xonsh hook)")
_sys.modules["xontrib.conda"] = _mod
del _sys, _mod, _ModuleType
# <<< conda initialize <<<

and

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/connor/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/connor/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/connor/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/connor/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

CodePudding user response:

The bash profile is a set up script which runs when you open the terminal, where in the script you provided it sets up the PATH environment variable. All the happens in those lines of code is that the base conda environment is added to the start of the path, so that if the os searches for any binary files (e.g. python) it first searches your conda and the currently activated environment. Since you deleted all anaconda files and its associated binaries, this bash_profile script should now do nothing.

So in short, the lines of code in your bash_profile was set up when you first installed anaconda, and was not present on your mac initially. You can delete the bash profile, and when you next install anaconda it will again automatically overwrite your bash profile to add conda to its path.

CodePudding user response:

None of these files (~/.bash_profile, ~/.zshrc, and ~/.xonshrc) exist by default in macOS, so if the Anaconda setup is the only thing there, it's safe to just delete them. With one slight caveat: it's possible some other file/script will assume they exist and try to source (or .) them; it might be worth grepping all the dotfiles in your home directory for occurrences of those filenames.

BTW, the default contents of a newly-created macOS user home directory are in /System/Library/User Template/* -- there's a .../Non_localized subdirectory with most of the contents, and per-language subdirectories (e.g. .../English.lproj) with language-specific additions. You can see what's there with:

sudo ls -lA '/System/Library/User Template/'{Non_localized,English.lproj}
  • Related