0

I'm trying to setup ruby using rbenv on a server, instead of the apt-get installed version of ruby and bundler.

I followed Digital Ocean's guide, deviating only on ruby version (I need 2.7.1) and ruby installation path (PREFIX=~/local ./ruby-build/install.sh) to keep everything in my home folder because I'm not root.

What worked

  • Installing rbenv
  • Installing ruby-build
  • rbenv install 2.7.1
  • rbenv shell 2.7.1
  • rbenv global 2.7.1
  • bundle install
  • sudo apt-get purge ruby

However bundle exec rake does not run, and returns the following error:

/usr/bin/env: ‘ruby2.7’: No such file or directory
$ rbenv exec bundle exec ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
$ rbenv exec bundle exec rake
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1

When I simply run rake in my application folder (without going through bundle exec) I get the following error:

$ rake
rake aborted!
LoadError: libruby-2.7.so.2.7: cannot open shared object file: No such file or directory - /home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/msgpack-1.4.2/lib/msgpack/msgpack.so
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/msgpack-1.4.2/lib/msgpack.rb:8:in `require'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/msgpack-1.4.2/lib/msgpack.rb:8:in `<top (required)>'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:4:in `require'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/explicit_require.rb:44:in `rescue in with_gems'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/explicit_require.rb:40:in `with_gems'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/store.rb:4:in `<top (required)>'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache.rb:61:in `require_relative'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache.rb:61:in `<top (required)>'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap.rb:5:in `require_relative'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap.rb:5:in `<top (required)>'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/setup.rb:2:in `require_relative'
/home/gchampenois/www/staging/shared/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/setup.rb:2:in `<top (required)>'
/home/gchampenois/www/staging/releases/20211126155023/config/boot.rb:4:in `require'
/home/gchampenois/www/staging/releases/20211126155023/config/boot.rb:4:in `<top (required)>'
/home/gchampenois/www/staging/releases/20211126155023/config/application.rb:1:in `require_relative'
/home/gchampenois/www/staging/releases/20211126155023/config/application.rb:1:in `<top (required)>'
/home/gchampenois/www/staging/releases/20211126155023/Rakefile:4:in `require_relative'
/home/gchampenois/www/staging/releases/20211126155023/Rakefile:4:in `<top (required)>'

It looks like running rbenv exec bundle exec rake [command] actually calls /usr/local/bin/bundle instead of rbenv's shim, despite having .rbenv/shims and .rbenv/bin first in my PATH.

Any idea why, and how to work around that?

Things I've tried already

  • gem update --system
  • rbenv rehash
  • removing and reinstalling rbenv entirely
  • installing ruby 2.7.0 through rbenv

Here's my environment:

$ echo $PATH
/home/gchampenois/.rbenv/shims:/home/gchampenois/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

$ lsb_release -a | grep 'Description'
Description:    Ubuntu 20.04.2 LTS

$ rbenv versions
* 2.7.1 (set by RBENV_VERSION environment variable)

$ which -a bundle
/home/gchampenois/.rbenv/shims/bundle
/usr/local/bin/bundle
/usr/bin/bundle
/bin/bundle

$ which -a gem
/home/gchampenois/.rbenv/shims/gem

$ which -a ruby
/home/gchampenois/.rbenv/shims/ruby

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

$ cat /usr/local/bin/bundle
#!/usr/bin/ruby2.7
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundle', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundle", version)
end

$ bundle env | head -n30
## Environment

Bundler       2.2.32
  Platforms   ruby, x86_64-linux
Ruby          2.7.1p83 (2020-03-31 revision a0c7c23c9cec0d0ffcba012279cd652d28ad5bf3) [x86_64-linux]
  Full Path   /home/gchampenois/.rbenv/versions/2.7.1/bin/ruby
  Config Dir  /home/gchampenois/.rbenv/versions/2.7.1/etc
RubyGems      3.2.32
  Gem Home    /home/gchampenois/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
  Gem Path    /home/gchampenois/.gem/ruby/2.7.0:/home/gchampenois/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
  User Home   /home/gchampenois
  User Path   /home/gchampenois/.gem/ruby/2.7.0
  Bin Dir     /home/gchampenois/.rbenv/versions/2.7.1/bin
Tools         
  Git         2.25.1
  RVM         not installed
  rbenv       rbenv 1.2.0-6-g304cb7b
  chruby      not installed

## Bundler Build Metadata

Built At          2021-11-23
Git SHA           20d4957649
Released Version  true

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.2.32
  - RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/gchampenois/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
  - USER INSTALLATION DIRECTORY: /home/gchampenois/.gem/ruby/2.7.0
  - RUBY EXECUTABLE: /home/gchampenois/.rbenv/versions/2.7.1/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/gchampenois/.rbenv/versions/2.7.1/bin
  - SPEC CACHE DIRECTORY: /home/gchampenois/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/gchampenois/.rbenv/versions/2.7.1/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
  - GEM PATHS:
     - /home/gchampenois/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
     - /home/gchampenois/.gem/ruby/2.7.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document --no-ri"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/gchampenois/.rbenv/versions/2.7.1/bin
     - /home/gchampenois/.rbenv/libexec
     - /home/gchampenois/.rbenv/plugins/ruby-build/bin
     - /home/gchampenois/.rbenv/shims
     - /home/gchampenois/.rbenv/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /snap/bin
Goulven
  • 101
  • 2

1 Answers1

0

I solved this by removing everything in <app_name>/vendor/bundle

rm -rf <app_name>/vendor/bundle

making sure that in my Gemfile I had

ruby '2.7.0'

and then.

gcloud config set app/cloud_build_timeout 86400

gcloud app deploy