Home > database >  Reset default $PATH variable MacOS 12
Reset default $PATH variable MacOS 12

Time:10-07

I'm using macOS 12 Monterey and bash shell.

.bash_profile

#Default PATH entries
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin


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



# Added by Toolbox App
export PATH="$PATH:/Users/mah_prince/Library/Application Support/JetBrains/Toolbox/scripts"eval $(/opt/homebrew/bin/brew shellenv)

.bash_profile.bak

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

When I type echo $PATH it returns

/opt/homebrew/bin:/opt/homebrew/sbin:"/opt/homebrew/bin:/opt/homebrew/sbin${PATH :$PATH}";

A lot of mac commands are also not available like which . Also, my installed nodejs, npm are not available.

But if I type

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Then the PATH is set and also all the commands are available again.

But if I restart the laptop, the PATH is again reset to the previous path and the commands are also not available again, and also my nodejs.

CodePudding user response:

Change

export PATH="$PATH:/Users/mah_prince/Library/Application Support/JetBrains/Toolbox/scripts"eval $(/opt/homebrew/bin/brew shellenv)

to

export PATH="$PATH:/Users/mah_prince/Library/Application Support/JetBrains/Toolbox/scripts"

eval $(/opt/homebrew/bin/brew shellenv)

The eval command should be on a separate line.

I suspect your .bash_profile didn't end in a newline, and the tool that added the eval command doesn't check for this, so it added it at the end of the line instead of the next line.

  • Related