Closed peterb closed 4 years ago
The reason the documentation recommends ~/.bashrc
or ~/.zshrc
, instead of ~/.bash_profile
or ~/.zprofile
, is because the profile
configure files are only loaded for interactive/login shell sessions. The rc
configuration files are loaded for both interactive and non-interactive shell sessions, allowing chruby to be used in scripts, etc.
I would instead double check whether macOS's bash is still ignoring ~/.bashrc
.
I'm sure that the OS X 10.14
ignores ~/.bashrc
, not sure about 10.15
. I didn't know about the difference between the *rc
and *profile
files, will add some details to the description and continue looking into it.
This should almost certainly be added to rc
instead of profiles. They serve very different purposes.
About macOS ignoring ~/.bashrc
, I don’t think that’s macOS specific. IIRC Bash just ignores ~/.bashrc
when it is the login shell, on all platforms. In Linux you can reproduce it (ignoring ~/.bashrc
) when you SSH into it; when you use X, then Bash won’t be your “login shell”.
Almost all Linux distribution pre-populates your ~/.bash_profile
with something like
# whether Bash is called with "-i" flag, stands for interactive
if [[ $- == *i* ]]
then source ~/.bashrc
fi
Finally if you are on macOS I would recommend Zsh, which is more up-to-date, and will be default since Catalina.
Thanks for the explanations @postmodern, @FranklinYu, I'm on Catalina now so I'll make sure I'm using zsh. Maybe it would be worth mentioning configuring with ˜/.zshrc
in Catalina instead of ˜/.bashrc
and ˜/.bash_profile
which more likely to be used on Linux.
By the way, there seems to be an issue with CI on this project, I've seen others finding workarounds such as merging in the master branch on other PRs, but mine seems to be up-to-date with master.
I think this in ReadMe suffices:
Add the following to the
~/.bashrc
or~/.zshrc
file:source /usr/local/share/chruby/chruby.sh
By the way, I don’t agree with the next line (added in #372):
Note: OSX does not automatically execute
~/.bashrc
, instead try adding to/etc/bashrc
.
I would consider creating a Pull Request to update that line to the correct instruction, as well as to explain why macOS behaves as if it ignores ~/.bashrc
. @postmodern Would you like that?
Unrelated note: you are using a tilde different from the one we are using. The one Bash would recognize is tilde (U+007E); you are using small tilde (U+02DC). Just FYI. 😄
@FranklinYu yes I would prefer a note or a section dedicated to how macOS's bash differs from regular bash.
@FranklinYu did you update this or shall I pick it up?
Summary
The experience of starting to use
chruby
on OS X is already really good compared to other systems. The idea is that this will make it a tiny bit better.Any comments just shout me!
Update
OS X doesn't source
~.bashrc
in interactive shell sessions (it should do so), but does source~.bash_profile
, so asking users to sourcechruby
in~.bash_profile
should means that they'll have fewer issues.Also, modifying files in
/etc/
makes it a lot harder to track down problems with the environment if they should occur.