我试图在Debian上安装我的Rails 5项目。无论是否bundle install
运行sudo
都会导致错误抱怨没有相应版本的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]
答案 0 :(得分:0)
当你调用bundle时,首先bundle
本身会在$PATH
中得到解决。您可以通过键入whereis bundle
或which 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
检查文件内容来检查这一点。
之后,您可以通过键入gem
:
whereis gem
的可用可执行文件
$ whereis gem
gem: /usr/bin/gem /usr/bin/gem2.2 /usr/bin/gem2.4
然后您可以通过键入gem uninstall bundler
(这也应该删除它的可执行文件)来删除bundler并使用正确的gem再次安装它,执行:
/usr/bin/gem2.4 install bundle
这应该可以解决问题,因为在Bundler的可执行文件中,你将获得Ruby 2.4作为解释器。
update-alternatives命令对这种情况也很有用。
正如您所看到的,这是一个令人头痛的问题,所以我建议使用Ruby版本管理器(rvm,rbenv等),或者每台机器只有一个Ruby版本。< / p>
答案 1 :(得分:0)
gem install rails --version 5.0.0