ruby-on-rails 您的Ruby版本是3.3.0.dev,但您的Gemfile指定为>= 3.3.0

holgip5t  于 2023-02-26  发布在  Ruby
关注(0)|答案(1)|浏览(214)

我有一个源代码编译版本的ruby(ruby 3.3.0dev (2023-02-18T11:34:28Z master cbac0fa4cb))。我做了一个ruby on rails项目,就像here描述的那样。我在步骤4.1,但是它抛出了这个错误:Your Ruby version is 3.3.0.dev, but your Gemfile specified >= 3.3.0.但不知何故即使
我把

ruby '>= 3.3.0'

到我的宝石文件,做了bundle updategem install bundler,但仍然抛出这个错误。

6ie5vjzr

6ie5vjzr1#

    • 溶液**:降低宝石文件的Ruby要求。选项包括
ruby '> 3.2' #or 
ruby '3.3.0.dev' #or
ruby '~> 3.3.a'
    • 说明**:

这个错误非常明显:
您的Ruby版本是www.example.com,但您的Gemfile指定为〉= 3.3.03.3.0.dev, but your Gemfile specified >= 3.3.0

Gem::Version.new('3.3.0.dev') >= Gem::Version.new('3.3.0')  
#=> false

根据版本比较,3.3.0.dev被视为小于3.3.0。(请参见:Gem::Version#<=>
例如:

# This is how Gem::Version#<=> works 

def comp(a,b)
  return 0 if a.send(:_version) == b.send(:_version) || a.canonical_segments == b.canonical_segments

  lhsegments = a.canonical_segments
  rhsegments = b.canonical_segments

  lhsize = lhsegments.size
  rhsize = rhsegments.size
  limit  = (lhsize > rhsize ? lhsize : rhsize) - 1

  i = 0

  while i <= limit
    lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
    i += 1

    next      if lhs == rhs
    return -1 if String  === lhs && Numeric === rhs
    return  1 if Numeric === lhs && String  === rhs

    return lhs <=> rhs
  end

  return 0
end

required = Gem::Version.new('3.3.0') 
current = Gem::Version.new('3.3.0.dev')

comp(required,current)
#=> 1

这里的关键是return 1 if Numeric === lhs && String === rhs这一行
细分如下:

  • 左分段=[3,3]
  • rhsegment =[3,3,"偏差"]
  • 前2次迭代得到next if lhs == rhs
  • 第三次迭代得到return 1 if Numeric === lhs && String === rhs,因为rhsString,并且得到lhs == 0,因为lhsegments[2] #=> nil

您可以使用以下公式找到"建议的近似值":

current.approximate_recommendation
#=> "~> 3.3.a"
new_required = Gem::Version.new('3.3.a') 
comp(new_required,required)
#=> -1 
comp(new_required,current) 
#=> -1

您可以看到,使用'~> 3.3.a'时,"www.example.com"或"3.3.0"都将满足此要求。3.3.0.dev' or '3.3.0' will satisfy this requirement.

相关问题