简体   繁体   English

Fedora 20上的Ruby on Rails

[英]Ruby on Rails on Fedora 20

I am using Fedora 20 and installed Ruby version 2.0 and Rails version 4.1.6. 我正在使用Fedora 20,并安装了Ruby 2.0版和Rails 4.1.6版。

I tried rails new example but got this error: 我尝试了rails new example但遇到了以下错误:

Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.11

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h


Gem files will remain installed in /home/sntr/.gem/ruby/gems/json-1.8.1 for inspection.
Results logged to /home/sntr/.gem/ruby/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
         run  bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

I tried gem install json -v '1.8.1' or sudo yum install json ... but it didn't change, I couldn't run Rails. 我尝试了gem install json -v '1.8.1'sudo yum install json ...但它没有改变,我无法运行Rails。

I tried gem install json -v '1.8.1' or sudo yum install json ... but it didn't change, I couldn't run Rails. 我尝试了gem install json -v'1.8.1'或sudo yum install json ...但它没有改变,我无法运行Rails。

System package would actually solve the problem, but you would need to lock its version in your Gemfile . 系统软件包实际上可以解决该问题,但是您需要将其版本锁定在Gemfile中

Perhaps you don't know that, but the whole Ruby on Rails framework is actually packaged, so running: 也许您不知道,但是实际上整个Ruby on Rails框架都是打包好的,因此运行:

# yum install rubygem-rails

will install Rails for you. 将为您安装Rails。 But since you will be most likely installing some other gems or their newer versions, install Ruby header files as well by installing the ruby-devel package: 但是,由于您很可能会安装其他一些gem或它们的较新版本,因此也可以通过安装ruby-devel软件包来安装Ruby头文件:

# yum install ruby-devel

Using system Ruby package is actually a good choice that is easy to install and gives you security updates among other things. 实际上,使用系统Ruby软件包是一个很好的选择,它易于安装,并且可以为您提供安全更新。 Using Ruby version manager is going to help you only if you need other version of Ruby that is not provided by your OS. 仅当您需要操作系统未提供的其他版本的Ruby时,使用Ruby版本管理器才能为您提供帮助。

Use RVM instead. 请改用RVM

If you are still new, it gives you an option for experimenting with different versions and environments. 如果您还不熟悉,它会为您提供一个尝试不同版本和环境的选项。

The problem here is that bundler doesn't use the system rubygems if newer versions are available from rubygems.org. 这里的问题是,如果可以从rubygems.org获得较新的版本,则捆绑程序不使用系统rubygems。 So, even if you have rubygem-json installed from Fedora packages, if for example it's version 1.8.1, it will be ignored because version 1.8.2 is in rubygems. 因此,即使从Fedora软件包安装了rubygem-json,例如,如果它的版本为1.8.1,它也会被忽略,因为版本1.8.2在rubygems中。

The same issue occurs with several other gems, but doesn't result in bundle failing unless the gem uses native extensions (ie C code that needs to be compiled). 其他几个gem也发生相同的问题,但是除非gem使用本机扩展(即,需要编译的C代码),否则不会导致捆绑失败。 Thus the json gem failed to install, but other gems will install successfully (from rubygems, not from yum). 因此,json gem无法安装,但是其他gem将成功安装(从rubygems,而不是yum)。

This issue was discussed in depth on Github , and unfortunately it has no easy solution , and not one that involves Bundler. 这个问题在Github上进行了深入的讨论 ,不幸的是, 它没有简单的解决方案 ,也没有涉及Bundler的问题。 Bundler is meant to ensure that, given a Gemfile/Gemfile.lock, that it installs exactly the versions of gems given, regardless of what system it's being run on. Bundler的目的是确保在给定Gemfile / Gemfile.lock的情况下,无论所运行的系统是什么,它都将准确安装给定的gem版本。

If you must use only system gems, then you need to create your app with rails new app --no-gemfile , install all of the necessary system gems yourself, and document which gems they are so that the gem installation can be repeated later for testing and deployment. 如果仅必须使用系统gem,则需要使用rails new app --no-gemfile创建应用,自己安装所有必需的系统gem,并记录它们是哪些gem,以便以后可以重复安装gem。测试和部署。 In particular, your app will not have a Gemfile or Gemfile.lock. 特别是,您的应用程序将没有 Gemfile或Gemfile.lock。 Typically you only need to do this if you're developing for deployment on a specific OS distribution (eg RHEL 7) and are only allowed to use system-provided packages anyway. 通常,仅当您要开发要在特定OS发行版(例如RHEL 7)上进行部署并且仅被允许使用系统提供的软件包时,才需要这样做。 This is common enough in enterprise software development. 这在企业软件开发中很常见。 If you aren't in this scenario, you should probably not use system ruby or rubygems at all, and prefer RVM. 如果您不在这种情况下,则可能根本不应该使用系统ruby或rubygems,而应该使用RVM。

只需在项目的根目录运行bundle update

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

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