You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Anaconda安装及执行source ~/.bashrc时出现command not found: shopt错误

Fixing "command not found: shopt" After Anaconda Installation

Hey there, let's break down why you're hitting that shopt error and how to fix it quickly:

What's causing this?

The shopt command is a bash-only built-in tool—it doesn't exist in other shells like zsh, fish, etc. When you run source ~/.bashrc in a non-bash shell, any bash-specific commands (like shopt) will throw a "command not found" error. Anaconda probably added some bash-specific config lines to your ~/.bashrc during installation, which triggers this when you're using a different default shell.

Step 1: Confirm your current shell

First, check which shell you're actually using:

echo $SHELL

If the output is something like /bin/zsh instead of /bin/bash, that's the root cause.

Step 2: Choose a fix that works for you

Pick one of these solutions based on your preference:

  • Switch to bash temporarily or permanently

    • To use bash just for this session: run bash, then execute source ~/.bashrc—the error should disappear, and Anaconda's environment will load correctly.
    • To set bash as your default shell (requires restarting your terminal):
      chsh -s /bin/bash
      
  • Move Anaconda's config to your shell's config file
    If you prefer sticking with your current shell (like zsh), open ~/.bashrc and copy the entire Anaconda initialization block—it looks like this:

    >>> conda initialize >>>
    !! Contents within this block are managed by 'conda init' !!

    __conda_setup="$('/path/to/conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
    eval "$__conda_setup"
    else
    if [ -f "/path/to/conda/etc/profile.d/conda.sh" ]; then
    . "/path/to/conda/etc/profile.d/conda.sh"
    else
    export PATH="/path/to/conda/bin:$PATH"
    fi
    fi
    unset __conda_setup

    <<< conda initialize <<<

    Paste this block into your shell's config file (e.g., ~/.zshrc for zsh), then run source ~/.zshrc—Anaconda will load without hitting the shopt error.

  • Guard the bash-specific code in ~/.bashrc
    If you want to keep ~/.bashrc compatible with other shells, wrap the shopt line (and any other bash-only commands) in a conditional that only runs in bash:

    if [ -n "$BASH_VERSION" ]; then
        # Your shopt command here, e.g.:
        shopt -s expand_aliases
    fi
    

    Now when you run source ~/.bashrc in a non-bash shell, this code will skip over the shopt command, avoiding the error.

内容的提问来源于stack exchange,提问作者Mohamed Baher

火山引擎 最新活动