How to remove (base) from terminal prompt after updating conda

89,439

Solution 1

Use the base env's activation hook

For each env, any scripts in the etc/conda/activate.d directory will be executed post-activation (likewise etc/conda/deactivate.d scripts for deactivation). If you add a script to remove the (base), similar to @ewindes suggestion, you'll get the behavior you desire.

I had to create this directory for base, which is just the root of your Anaconda/Miniconda folder. E.g.,

mkdir -p miniconda3/etc/conda/activate.d

Then made a simple file in there (e.g., remove_base_ps1.sh) with one line:

PS1="$(echo "$PS1" | sed 's/(base) //') "

If you are using zsh, use this instead.

PROMPT=$(echo $PROMPT | sed 's/(base) //')

Launching a new shell then does not show (base), and deactivating out of nested envs also takes care of the PS1 change.

Note: You must add quotes around $PS1 if you want to preserve ending spaces.

Solution 2

That's because conda's base environment is activated on startup.

To set the auto_activate_base parameter to false, type:

conda config --set auto_activate_base false


Edited 2021/09/09:

If you are facing the exact same situation as the OP, that you are using conda to manage environments, and wanted to make (base) environment looks no different to system environment in terminal, check @merv 's answer for the procedures. Note that the prompt string is stored in a certain special variable, depending on the shell you are using, so check the documentation of your shell if it does not work for you.

If you want to use the system environment and not using conda at all, my original answer was the solution for you.

Thanks to @merv and @Neinstein for pointing out in the comments.

Solution 3

By default, auto_activate_base is set to True when installing anaconda. To check this, run:

$ conda config --show | grep auto_activate_base
auto_activate_base: True

To set it False

conda config --set auto_activate_base False

and vice-versa.

Note, if changeps1 is kept False, it will hide (env) completely, and in case you want to show (env) only when it's activated, you can set changeps1 to True:

conda config --set changeps1 True

Setting changeps1 to False will hide (env) even if the env is activated and will keep hiding (base) even after auto_activate_base is set to True.

Solution 4

You could add a command to your .bashrc to remove the "(base)" string from PS1:

PS1=$(echo $PS1 | sed 's/(base)//')

Solution 5

For me, what worked was:

conda config --set changeps1 false 
Share:
89,439

Related videos on Youtube

Homero Esmeraldo
Author by

Homero Esmeraldo

Computer Engineer and Graduate student in Computational Neuroscience.

Updated on April 07, 2022

Comments

  • Homero Esmeraldo
    Homero Esmeraldo about 2 years

    After updating miniconda3, whenever I open a terminal it shows "(base)" in front of my username and host.

    In this answer post https://askubuntu.com/a/1113206/315699 it was suggested to use

    conda config --set changeps1 False
    

    To remove it.

    But that would remove the indication for any conda environment. I would like to remove it only for the base one, so that I can maintain it always active and have access to its python and installed packages without having to always see this (base) taking up space.

  • David
    David about 5 years
    Your answer adds a space at the beginning of PS1 and removes a space after $, so the text looks like: _rosgori@sa6:~$cd Documents/. This line improves that: PS1="$(echo $PS1 | sed 's/(base) //') ", unfortunately, when you activate another env, then deactivate, the (base) will be there.
  • merv
    merv over 4 years
    The issue in OP is that they don't want the PS1 change even when base is activated.
  • ether_joe
    ether_joe over 4 years
    this is what I was looking for.
  • merv
    merv almost 4 years
    What does this add that is not already in this other early answer?
  • merv
    merv over 3 years
    That removes it for everything - please reread the OP (only wants change for base). Even if this was what was desired, changeps1 would be more effective; this solution still results in running code to manage PS1 even though it only ever inserts empty strings.
  • Homero Esmeraldo
    Homero Esmeraldo over 3 years
    You should make sure you know what is the consequence of commenting these lines apart from removing "base" from the shell label.
  • Ed Griebel
    Ed Griebel over 3 years
    This is the one that worked for me in zsh with OhMyZsh on macOS Catalina (10.15) when the accepted answer didn't, probably because prompts are done slightly differently than bash
  • Awaaaaarghhh
    Awaaaaarghhh over 3 years
    Doesn't work for me (conda 4.8.3; Python 3.8.3). I have still the same "(base)" in my shell.
  • merv
    merv over 3 years
    @Awaaaaarghhh ask a new question with details on how it failed and I'll have a look. Include the output of conda info in the question.
  • Awaaaaarghhh
    Awaaaaarghhh over 3 years
    @merv probably one just need to reboot the PC after executing your commands. - Just restarting the shell didn't help.
  • merv
    merv over 3 years
    I strongly recommend against this. Those double exclamation warnings are there to indicate that you shouldn't edit this region. Plus, this removes all the newer Conda v4.4+ shell functionality and leaves only the pre-v4.4 PATH management which the devs only include as an absolute baseline fallback (e.g., for unsupported shells only).
  • memeplex
    memeplex over 3 years
    There is an extra space at the end. OTOH there is no need to add the double quotes in this kind of bash assignments.
  • ceremcem
    ceremcem over 3 years
    [[ $PS1 =~ ^\(base\) ]] && conda config --set auto_activate_base false persistent between (re)installations. (Add it into ~/.bashrc, after Conda's section)
  • Zaki Aziz
    Zaki Aziz about 3 years
    @merv you can do that by running this: conda config --set changeps1 false
  • merv
    merv about 3 years
    @ZakiAziz that affects all environments. OP only wants base environment not to change PS1, other envs should still change it. Many people seem to end up on this question, when really they want to prevent base auto-activation or prevent editing PS1.
  • merv
    merv about 3 years
    But how do you get this to only prevent it for base and no other environment? That is OP's question. This is instead answering this question.
  • Neinstein
    Neinstein almost 3 years
    This does not make the (base) prefix hidden for the base environment, this makes the base environment not activate at all. The shell will use the system Python, not the Anaconda one! This is not what OP wants at all, and it will cause a lot of problem for inexperienced users. If you do a conda activate, the (base) conda prefix will appear, as you actually load it. The fact this answer has 98+ upvotes show how harmful it is - 98 people thought they solved this problem, while they didn't.
  • Yokissa
    Yokissa over 2 years
    @Neinstein You are right in saying that this is not the correct answer to the OP's question. I was not aware that conda was used to manage environments when I answered this question and it was my intention to go back to use the system environment when my search end up at this question, so I left my solution here. I will edit the answer accordingly.
  • rbatty19
    rbatty19 about 2 years
    it worked, but is also important to have run conda config --set auto_activate_base false
  • Manishyadav
    Manishyadav about 2 years
    okk i'll keep this in mind!!
  • water stone
    water stone about 2 years
    there is nothing wrong commenting out or simply removing those lines, you can also choose not to let conda to add those lines to your .bashrc. as long as you set the PATH etc env variables to your preference, there is no need for these lines to exist