我正在尝试在服务器上使用 rbenv 设置 ruby,而不是使用 apt-get 安装的 ruby 和 bundler 版本。
我跟着Digital Ocean 的指南,仅在 ruby 版本(我需要 2.7.1)和 ruby 安装路径(PREFIX=~/local ./ruby-build/install.sh
)上有所偏差,因为我不是 root,所以将所有内容都保存在我的主文件夹中。
有效的方法
- 安装 rbenv
- 安装 ruby-build
rbenv install 2.7.1
rbenv shell 2.7.1
rbenv global 2.7.1
bundle install
sudo apt-get purge ruby
但是bundle exec rake
不运行,并返回以下错误:
/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
当我简单地在我的应用程序文件夹中运行rake
(没有经过bundle exec
)时,我收到以下错误:
$ 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)>'
看起来像在跑步rbenv exec bundle exec rake [command]
实际上调用/usr/local/bin/bundle
而不是 rbenv 的 shim,尽管在我的 中有.rbenv/shims
and .rbenv/bin
first PATH
。
知道原因是什么吗?如何解决?
我已经尝试过的事情
gem update --system
rbenv rehash
- 彻底删除并重新安装 rbenv
- 通过 rbenv 安装 ruby 2.7.0
这是我的环境:
$ 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
答案1
我通过删除 <app_name>/vendor/bundle 中的所有内容解决了这个问题
rm -rf <应用程序名称>/vendor/bundle
确保我的 Gemfile 中有
ruby'2.7.0'
进而。
gcloud 配置设置 app/cloud_build_timeout 86400
gcloud 应用部署