When building the environment, I thought I would install Homebrew, so I installed brew and set bash_profile.

$echo'export PATH = "~/.rbenv/shims: /usr/local/bin: $PATH"' >>~/.bash_profile
$echo'eval "$(rbenv init-)"'>>~/.bash_profile
$source ~/.bash_profile

And after typing the last command

(eval): 18: parse error near `PATH = ~/.rbenv/shims: ...'

It will result in an error.
I checked the contents of .bash_profile,

# eval "$(rbenv init-)"
# eval "$(rbenv init-)"
[[-d ~/.rbenv]]&&\
  export PATH = ${HOME} /. Rbenv/bin: ${PATH}&&\
  eval "$(rbenv init-)" export PATH = "~/.rbenv/shims:/usr/local/bin: $PATH"
eval "$(rbenv init-)"
eval "$(rbenv init-)"
export PATH = "~/.rbenv/shims: usr/local/bin: $PATH"
eval "$(rbenv init-)"

It looks like this and it looks strange, but I can't understand the details, so I can't touch it. Sweat
I would be grateful if you could give me some advice.

  • Answer # 1

    if which rbenv>/dev/null;then eval "$(rbenv init-)";fi

    You only need to write this one line in your .bash_profile or .zprofile.
    Since init will automatically add it to your PATH, you do not need to describe the PATH setting.
    (Rbenv itself is under/usr/local/bin.)

  • Answer # 2

    Environment variable settings,

    $echo ~~ >>~/.bash_profile

    It is better not to trust the page that says.

    It looks like this and it seems strange to see it,

    Yes. It's funny.
    Delete all that part and instead

    export PATH = ~/.rbenv/shims: /usr/local/bin: $PATH
    eval "$(rbenv init-)"

    Please write two lines.

    However, isn't Mac using Zsh instead of Bash?
    In the case of Zsh, the file to be set is different.~/.zprofileis not it.