developer-portal / content

Content for the Fedora Developer Portal
https://developer.fedoraproject.org/
GNU General Public License v2.0
107 stars 253 forks source link

: web-app rails.md #494

Closed dirschn closed 10 months ago

dirschn commented 11 months ago

I noticed today that the Ruby on Rails guide mentions

Whenever you install a new version of Ruby or a gem, you should run the rehash sub-command. This will make rails executables known to rbenv, which will allow us to run those executables:

I was a little confused because I haven't manually run that command ever and haven't had any issues, so I took a look at the rbenv GitHub page and in the rbenv rehash section it mentions that rbenv rehash is run automatically when installing gems. It seems to me that there's no need to run it manually after installing new versions or gems?

Apologies if I have the format of creating a new issue wrong, I couldn't find any format requirements!

jackorp commented 11 months ago

Thanks for taking time sharing this!

Yeah we were discussing this recently on some rbenv related pull request whether that's needed, we left it there due to not being sure. Thanks for finding the reference that it isn't needed, We can fix that with confidence now.

Alternatively, you can edit the page yourself here: https://github.com/developer-portal/content/blob/master/start/sw/web-app/rails.md , we have some related info for contributing here: https://developer-portal.github.io/contributing/

dirschn commented 11 months ago

I can make the edit either later today or sometime tomorrow, if you like! I've been wanting to get into open source contributions so why not start here!

benmelz commented 11 months ago

Coworker of @dirschn here, with a small gotcha. I'm observing with rbenv 1.2.0-80-gd6bb1c6 that while gem install appears to trigger automatic rehashing, bundle does not.

We include the following in our setup script, haven't added cli tools in a while, and strongly encourage binstub/bundle exec usage, hence @dirschn's confusion

  system('bundle check') || system!('bundle install')
  system('if command -v rbenv &> /dev/null; then rbenv rehash; fi')

Since the majority of rails devs will be installing tools via bundle, that might warrant leaving this section in for now at least (perhaps open an issue with the rbenv team to expand functionality to bundle? and then this could be removed).

jackorp commented 11 months ago

Huh, that's interesting behavior. So to get my mental notes on this straight:

The following triggers a rehash:

gem install foo-bar-with-executable

While the following command in a project with a Gemfile containing entry for gem foo-bar-with-executable:

bundle install

will not then execute rehash and therefore foo-bar-with-executable will not be available correctly?

I am a little bit confused as I have not yet had the need for bundler + rbenv combo, is it regularly expected that bundle install would make foo-bar-with-executable available on regular path with rbenv after a rehash?

A rewording or similar might be warranted though if it works for all but bundler environments.

benmelz commented 11 months ago

Huh, that's interesting behavior. So to get my mental notes on this straight:

The following triggers a rehash:

gem install foo-bar-with-executable

While the following command in a project with a Gemfile containing entry for gem foo-bar-with-executable:

bundle install

will not then execute rehash and therefore foo-bar-with-executable will not be available correctly?

Yes that's correct.

I am a little bit confused as I have not yet had the need for bundler + rbenv combo, is it regularly expected that bundle install would make foo-bar-with-executable available on regular path with rbenv after a rehash?

A rewording or similar might be warranted though if it works for all but bundler environments.

So after some more investigation, I've figured out that this is in fact a bug with rbenv - https://github.com/rbenv/rbenv/issues/1540 (i.e. there is code for automatic rehashing specifically for bundle install, but it doesn't work).

benmelz commented 11 months ago

Update: patch has been accepted and merged in rbenv/rbenv:master so now this issue as initially described is accurate, assuming an up-to-date rbenv.

I'll caution that there hasn't been an "official" release of rbenv in 2 years so it's likely only people who install via git will get it for a while (depending on the different package manager formulae definitions).

jackorp commented 11 months ago

Thanks! I think it should now be adjusted to say to either update rbenv (with reference to either this discussion or rather the upstream PR) if pulled via git by user or state that in the other case the rehash is needed for bundler install :) Either way, we have an answer for whether it's needed, if any of you would manage to write something up, I'd immensely appreciate it.

jackorp commented 11 months ago

I have created #498, I also fixed up the styling and whatnot on the page. If you want to, you can check the section regarding rbenv on the PR and review it.

dirschn commented 11 months ago

That's my bad, it was a busy week and this slipped my mind. I'll take a look when I get home from work.

jackorp commented 10 months ago

Thanks to you both, for helping with reviews, collaboration, and reporting/fixing the bug upstream. All of these contributions are very much appreciated.