rbenv / rbenv

Manage your app's Ruby environment
https://rbenv.org/
MIT License
16.04k stars 1.39k forks source link

Commands are not automatically created in shim #1585

Open Sherry520 opened 3 weeks ago

Sherry520 commented 3 weeks ago

I use bundle install to install asciidoctor-pdf-cjk-kai_gen_gothic-install from github. My Gemfile looks like this:

source 'https://rubygems.org'

gem 'rubyzip', '2.3.2'
gem 'ffi', '1.16.3'
gem 'rake'
gem 'asciidoctor', '2.0.12'

gem 'json'
gem 'awesome_print'

gem 'ttfunk', '1.5.1'
gem 'asciidoctor-fb2'
gem 'asciidoctor-epub3', '1.5.0.alpha.11'
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
gem 'asciidoctor-pdf-cjk', '~> 0.1.3'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', github: 'Sherry520/asciidoctor-pdf-cjk-kai_gen_gothic'

gem 'coderay'
gem 'pygments.rb'
gem 'thread_safe'
gem 'epubcheck-ruby'
gem 'html-proofer'

When I run bundle install, things look good: image

But it didn't work, I have tried the method mentioned in Understanding-binstubs : image

It looks like this command does not exist in shim: image

Environment

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.1.6
  - RUBY VERSION: 2.7.8 (2023-03-30 patchlevel 225) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/gyh/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /home/gyh/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /home/gyh/.rbenv/versions/2.7.8/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/gyh/.rbenv/versions/2.7.8/bin
  - SPEC CACHE DIRECTORY: /home/gyh/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/gyh/.rbenv/versions/2.7.8/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/gyh/.rbenv/versions/2.7.8/lib/ruby/gems/2.7.0
     - /home/gyh/.gem/ruby/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/gyh/.rbenv/versions/2.7.8/bin
     - /home/gyh/.rbenv/libexec
     - /home/gyh/.rbenv/plugins/ruby-build/bin
     - /home/gyh/.rbenv/shims
     - /home/gyh/.rbenv/bin
     - /home/gyh/software/docx2txt-1.4
     - /home/gyh/.local/bin
     - /home/gyh/software/admixture_linux-1.3.0
     - /home/gyh/software/spack/bin
     - /home/gyh/software/PopLDdecay-3.42/bin
     - /home/gyh/software/meme/bin
     - /home/gyh/software/meme/libexec/meme-5.5.5
     - /home/gyh/software/openmpi/bin
     - /home/gyh/software/plink_linux_x86_64
     - /home/gyh/perl5/bin
     - /home/gyh/.rbenv/shims
     - /home/gyh/.rbenv/bin
     - /home/gyh/.local/bin
     - /home/gyh/bin
     - /home/gyh/software/docx2txt-1.4
     - /home/gyh/.local/bin
     - /home/gyh/software/admixture_linux-1.3.0
     - /home/gyh/software/spack/bin
     - /home/gyh/miniconda3/condabin
     - /home/gyh/software/PopLDdecay-3.42/bin
     - /home/gyh/software/meme/bin
     - /home/gyh/software/meme/libexec/meme-5.5.5
     - /home/gyh/software/openmpi/bin
     - /home/gyh/software/plink_linux_x86_64
     - /home/gyh/perl5/bin
     - /usr/local/Modules/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /usr/lib/wsl/lib
     - ....(more not list)
Sherry520 commented 3 weeks ago

Updating bundler to 2.4.22 worked fine, but it was difficult to enable the default use of the new version of bundler, and it somehow succeeded. Can you test if there is a problem with bundler2.1.4? Can you change the default configuration and use bundler2.4.22 for ruby2.7.8?

mislav commented 3 weeks ago

Hi, when you install gems using bundle install, rbenv won't generally know about their executables nor add them to rbenv shims. This is not related to any specific Bundler version. Let me explain.

Using plain RubyGems and not Bundler, when you do gem install asciidoctor (I've abbreviated the name of the gem for the sake of readability), RubyGems will by default place the asciidoctor executable alongside the ruby executable for that Ruby version and rbenv will pick that up and generate an asciidoctor shim in ~/.rbenv/shims/ascidooctor. Thus, a gem gets installed "globally" for that specific Ruby version that was active at the time gem install ran.

However, when you do bundle install in a project that uses the "asciidoctor" gem, those gems are only installed in the project directory that contains the Gemfile, and no gem binstubs are ever generated. After running bundle install, there is no asciidoctor executable in that Ruby version nor in the directory of the project that contains the Gemfile. Instead, to run executables of gems that are in your current bundle, you need to use bundle exec <command>.

However, constantly writing bundle exec asciidoctor… would quickly get tedious. So, making gem binstubs easily accessible to your project can be useful. To generate gem binstubs, you've already discovered that you need to run the bundle binstubs command, but you have tried to run asciidoctor command too quickly afterwards. You see, the asciidoctor binstub was generated, but it wasn't in the PATH and thus you can't run it just by typing its name. It was placed in the local ./bin directory by default, which is not in PATH, and therefore you can only activate it by executing bin/asciidoctor instead.

To make it easier for yourself, you could add ./bin to your global PATH so you don't have to prefix your executables with relative paths, but plenty of developers will warn you that this practice applied globally to your system could be dangerous because someone could exploit that via malicious executables placed in bin/ directories. Personally, I use the direnv tool to only add ./bin directories of projects to PATH that I have explicitly allow-listed.