Better rbenv init instructions for bash #305

Closed
mislav opened this Issue Jan 3, 2013 · 9 comments

Projects

None yet

4 participants

@mislav
Collaborator
mislav commented Jan 3, 2013

Currently we say:

  • .bash_profile
  • .zshenv (in README) or .zshrc (in rbenv init)
  • .profile

.bash_profile is good advice for OS X, but bad on Linux (Ubuntu being an example). .zshenv gets sourced for every zsh started, and that's certainly not what we want.

I've written up a guide on our wiki about shell initialization in general:
https://github.com/sstephenson/rbenv/wiki/Unix-shell-initialization

For zsh we should always suggest .zshrc.

I don't know what to suggest to bash users on Ubuntu: for them .profile would be best and affect all programs running in that desktop session, but then they have to restart their desktop manager to re-read the file (or source it manually). .bashrc is read on every Terminal window/tab open, but that is the opposite behavior of OS X.

@mislav
Collaborator
mislav commented Jan 4, 2013

Fixed zshenv -> zshrc in c6855e0. References #224 #173 #212

Now the question remains which config file to suggest for bash. Idea: have rbenv init figure it out during runtime, based on environment.

@dnch
dnch commented Feb 5, 2013

It's worth noting that the default .profile on Ubuntu executes/includes .bashrc if it exists anyway:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

Having rbenv init trying to do any sort of determination (IMO) defeats the beauty of its simplicity—I kinda like the fact that rbenv is 'dumb' and doesn't seem to try to figure things out for me.

I'm inclined to suggest that perhaps it's not possible to get away with a simple one-liner in the documentation; if you're using a tool like rbenv, you should probably learn a little bit more about how your development environment actually works. Simply telling people to paste snippets of code in files isn't helpful in the long-run.

Then again, that's really outside the scope of this issue, isn't it?

@nihilismus

"Simply telling people to paste snippets of code in files isn't helpful in the long-run, you should probably learn a little bit more about how your development environment actually works".

👍 @DanCheail

I think that it would be helpful to tell how our environment should be, for instance:

  • Your shell should not read it's configuration file each time is executed (even login or interactive mode) because ... and ...
  • You can check if your shell has this behavior doing ... and ... test
  • You can set your environment in a workable state with ... and ... knowing that ... would be the consequences.
  • You should have in mind your development and production shell-environment.

So we can have something like rbenv best practices :)

@mislav
Collaborator
mislav commented Feb 5, 2013

I'm inclined to suggest that perhaps it's not possible to get away with a simple one-liner in the documentation; if you're using a tool like rbenv, you should probably learn a little bit more about how your development environment actually works.

@DanCheail: That would be ideal, but sadly we can't count on this prior knowledge with our users. Most people still seem to struggle with just the simple concept of PATH or how to configure it.

@dnch
dnch commented Feb 5, 2013

@mislav: A point I have to concede. RTFM should never be a valid answer.

Re-reading, the issue of Linux in a desktop vs server context is one I hadn't considered. Perhaps the distinction is worth noting?

Linux Desktop: .profile
Linux Server: .bashrc

@agrimm
agrimm commented Apr 3, 2013

I'm in the process of installing rbenv on an Ubuntu box (to be used more or less as a desktop, not as a server). Doing exec $SHELL -l works, but otherwise I get told "The program 'rbenv' is currently not installed. You can install it by typing: sudo apt-get install rbenv".

I suspect I can google to get "an" solution, but I suspect that there's multiple ways of doing it, and I'd rather choose the solution that's the most idiomatic.

@mislav
Collaborator
mislav commented Apr 3, 2013

@agrimm So every time you open a terminal, you have to exec $SHELL -l? I'm guessing that you've put the configuration in ~/.profile. Does logging out the desktop session and logging back in help with this? How about restarting the computer?

It's unfortunate that you're tripping up on this. I'd like us to come up with a solid solution for all platforms, but I don't see it yet.

@agrimm
agrimm commented Apr 4, 2013

Changing ~/.profile to ~/.bashrc in both steps 2 and 3 Works For Me(TM) as a (more or less) desktop user on Ubuntu. Changing only step 3 gives me

The program 'rbenv' is currently not installed. You can install it by typing:
sudo apt-get install rbenv

@agrimm
agrimm commented May 9, 2013

The problem I had seems to be related to using Ubuntu via nX, rather than logging in directly. http://askubuntu.com/questions/281863/ensuring-profile-gets-executed-when-using-nx

@mislav mislav added a commit that closed this issue Oct 3, 2013
@mislav mislav better Ubuntu Desktop installation instructions
Don't suggest that they add to their `.profile` anymore because:

1. They would have to restart the desktop session for their change to be
   reflected, or source the file manually;
2. An error in `.profile` may prevent logging in;
3. The `rbenv()` shell function and shell completions won't be available
   in Terminal since it doesn't start bash in login mode by default.

Therefore, suggest that they use `.bashrc` instead. This will be
immediately reflected in a new Terminal tab. If bash is started in login
mode somehow, the default `.profile` is set up to source `.bashrc` anyway.

Also, don't suggest restarting the shell environment with
`exec $SHELL -l`, since we don't know what was the original mode that
their shell was started in. (OS X Terminal.app will be login mode,
Ubuntu Terminal has non-login mode by default.) Mode can be checked with:

* bash: `shopt -q login_shell`
* zsh: `[[ $options[login] = "on" ]]`

But since this is gnarly, let's just avoid it altogether and go the
easy route.

Closes #305, fixes #373, reverts #286
a1fb5b1
@mislav mislav closed this in a1fb5b1 Oct 3, 2013
@cehoffman cehoffman pushed a commit to cehoffman/rbenv that referenced this issue Apr 8, 2014
@mislav mislav better Ubuntu Desktop installation instructions
Don't suggest that they add to their `.profile` anymore because:

1. They would have to restart the desktop session for their change to be
   reflected, or source the file manually;
2. An error in `.profile` may prevent logging in;
3. The `rbenv()` shell function and shell completions won't be available
   in Terminal since it doesn't start bash in login mode by default.

Therefore, suggest that they use `.bashrc` instead. This will be
immediately reflected in a new Terminal tab. If bash is started in login
mode somehow, the default `.profile` is set up to source `.bashrc` anyway.

Also, don't suggest restarting the shell environment with
`exec $SHELL -l`, since we don't know what was the original mode that
their shell was started in. (OS X Terminal.app will be login mode,
Ubuntu Terminal has non-login mode by default.) Mode can be checked with:

* bash: `shopt -q login_shell`
* zsh: `[[ $options[login] = "on" ]]`

But since this is gnarly, let's just avoid it altogether and go the
easy route.

Closes #305, fixes #373, reverts #286
8c38803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment