繁体   English   中英

如何告诉bundle install在PATH上使用Ruby版本?

[英]How do I tell bundle install to use the version of Ruby on my PATH?

我正在尝试在Debian上安装我的Rails 5项目。 运行带有或不带有sudo bundle install导致一个错误,抱怨没有合适的Ruby版本,即使我之后运行ruby -v ,也可以看到版本为2.4。 如何将bundle install指向正确的版本?

$ sudo bundle install
[sudo] password for myuser:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Your Gemfile lists the gem jquery-rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.3

Gem::InstallError: activesupport requires Ruby version >= 2.2.2.
An error occurred while installing activesupport (5.0.4), and Bundler cannot continue.
Make sure that `gem install activesupport -v '5.0.4'` succeeds before bundling.

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [armv6l-linux-eabihf]

没有sudo运行:

$ bundle install
Your Gemfile lists the gem jquery-rails (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Using rake 12.0.0
Using concurrent-ruby 1.0.5
Using i18n 0.8.6
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.3

Gem::InstallError: activesupport requires Ruby version >= 2.2.2.
An error occurred while installing activesupport (5.0.4), and Bundler cannot continue.
Make sure that `gem install activesupport -v '5.0.4'` succeeds before bundling.

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [armv6l-linux-eabihf]

调用捆绑软件时,首先, bundle本身会在$PATH得到解析。 您可以通过键入whereis bundlewhich bundle检查其可执行文件所在的位置。 就我而言(Ubuntu 16.04),它位于/usr/local/bin/bundle

如果执行cat /usr/local/bin/bundle ,我们将获得此可执行文件的内容:

$ cat /usr/local/bin/bundle
#!/usr/bin/ruby2.4
#
# 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"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

load Gem.activate_bin_path('bundler', 'bundle', version)

如您所见,这是一个简单的Ruby脚本,最上面的行( #!/usr/bin/ruby2.4 )设置解释器来执行它。

我想,在您的情况下,使用的是旧版本的Ruby,因为如果在安装2.4.0之前您的系统中装有Ruby, gem可执行文件就不会更新为2.4,并且还使用旧的Ruby版本。 您可以通过执行which gem (对我来说是/usr/bin/gem )并使用cat检查文件内容来进行检查。

之后,您可以通过键入whereis gem来检查gem的可用可执行文件:

$ whereis gem
gem: /usr/bin/gem /usr/bin/gem2.2 /usr/bin/gem2.4

然后,您可以通过输入gem uninstall bundler来删除捆绑器(这也将删除其可执行文件),然后使用正确的gem重新安装它,执行:

/usr/bin/gem2.4 install bundle

这应该可以解决问题,因为在Bundle的可执行文件中,您将获得Ruby 2.4作为解释器。

update-alternatives命令在这种情况下也很有用。

如您所见,这令人头疼,所以我的建议是使用Ruby版本管理器( rvmrbenv等),或者每台计算机仅使用一个Ruby版本。

gem install rails --version 5.0.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM