asdf-vm / asdf-ruby

Ruby plugin for asdf version manager
https://github.com/asdf-vm/asdf
MIT License
650 stars 133 forks source link

asdf in background #393

Closed nikhilbhatt closed 4 months ago

nikhilbhatt commented 4 months ago

When running gem install rake from terminal, zshrc gets loaded and gem install rake command runs successfully.

Now when I am trying to run it as background process gem intall rake it will not work. workaround for this will be to use full path.

$HOME/.asdf/shims/gem install rake By running this it introduces new error. here in below line we are using asdf directly. because in background we can not use asdf directly.

https://github.com/asdf-vm/asdf-ruby/blob/b73efbe3a57faefa0e42bc8fa411331976495f82/rubygems-plugin/rubygems_plugin.rb#L15

Please let me know If I am missing something here. or is there any other way to handle this?

Stratus3D commented 4 months ago

Now when I am trying to run it as background process gem intall rake it will not work.

Can you provide details on this? How did it not work? Did it print an error?

Also, how did you run it as a background process?

nikhilbhatt commented 4 months ago

Error log for the bundle install I just updated actual path with $HOME in logs.

Errno::ENOENT: No such file or directory - asdf
  $HOME/.asdf/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:5:in ``'
  $HOME/.asdf/plugins/ruby/rubygems-plugin/rubygems_plugin.rb:5:in `install'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/installer.rb:89:in `block in run'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/process_lock.rb:12:in `block in lock'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/process_lock.rb:9:in `open'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/process_lock.rb:9:in `lock'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/installer.rb:71:in `run'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/installer.rb:23:in `install'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/cli/install.rb:62:in `run'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/cli.rb:261:in `block in install'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/settings.rb:130:in `temporary'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/cli.rb:260:in `install'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/cli.rb:34:in `dispatch'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/cli.rb:28:in `start'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/exe/bundle:37:in `block in <top (required)>'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
  $HOME/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.19/exe/bundle:29:in `<top (required)>'
  $HOME/.asdf/installs/ruby/3.1.2/bin/bundle:25:in `load'
  $HOME/.asdf/installs/ruby/3.1.2/bin/bundle:25:in `<main>'

Also, how did you run it as a background process?

I am using chef to run bundle install. command ran -> $HOME/.asdf/shims/bundle install

Stratus3D commented 4 months ago

You should never invoke shims directly. Instead of $HOME/.asdf/shims/bundle install you should run bundle install or asdf exec bundle install. Regardless, the asdf code will determine the version by looking at the directory the command was invoked in.

I don't know where Chef is invoking your bundle install command, but if you don't have a Ruby version set for that directory in asdf it won't work and would typically print a message like this:

unknown command: shellcheck. Perhaps you have to reshim?

It's not clear to me what the stacktrace above means, as that's not from asdf, but I'd double check that you've followed all the steps in the asdf installation instructions.

nikhilbhatt commented 4 months ago

It's different error, Actually I got this working after loading up the environment variables when running the command,