error: failed to build gem native extension when installing rails on mac mountian lion os

后端 未结 4 1334
谎友^
谎友^ 2020-12-05 04:39

I\'ve recently updated to Mountain Lion and re-installed Ruby, but when I try to run a test Rails app, I get an error message that says that \"Rails is not currently install

相关标签:
4条回答
  • 2020-12-05 04:53

    I see that you are using ruby 1.9.3 using rvm on OS X 10.8.2 (Mountain lion) It's possible that some gems referenced by rails need gcc-4.2 in /usr/bin to build native estension.

    In Mountain Lion , even after installing Xcode 4.5 CLI tools ( opening the menu XCode - Preferences..Download -> Command Line Tools ) you get /usr/bin/gcc but not /usr/bin/gcc-4.2; unfortunately the build process of some native extension relies on /usr/bin/gcc-4.2

    However I just installed rails smoothly on an environment such as your. I previously fixed the environment as discussed in the Carina C. Zona's blog post: Fix for “make: /usr/bin/gcc-4.2: No such file or directory”, that is:

    • make sure you have installed Homebrew

      brew --version

      should report 0.9.3 or greater

      • if you have not brew than follow these instrunctions to install it
      • if you have a older version then update it:

      brew update

    • now you can install gcc-4.2 and create a symbolink link where is aspected by the build system

      brew tap homebrew/dupes

      brew install apple-gcc42

      sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2

    • now you're ready to successfully install rails

      gem install rails

    You should get output something like this

    Fetching: i18n-0.6.1.gem (100%)
    Fetching: activesupport-3.2.8.gem (100%)
    Fetching: builder-3.0.4.gem (100%)
    Fetching: activemodel-3.2.8.gem (100%)
    Fetching: rack-cache-1.2.gem (100%)
    Fetching: rack-test-0.6.2.gem (100%)
    Fetching: journey-1.0.4.gem (100%)
    Fetching: hike-1.2.1.gem (100%)
    Fetching: sprockets-2.1.3.gem (100%)
    Fetching: erubis-2.7.0.gem (100%)
    Fetching: actionpack-3.2.8.gem (100%)
    Fetching: arel-3.0.2.gem (100%)
    Fetching: tzinfo-0.3.34.gem (100%)
    Fetching: activerecord-3.2.8.gem (100%)
    Fetching: activeresource-3.2.8.gem (100%)
    Fetching: polyglot-0.3.3.gem (100%)
    Fetching: treetop-1.4.12.gem (100%)
    Fetching: mail-2.4.4.gem (100%)
    Fetching: actionmailer-3.2.8.gem (100%)
    Fetching: rack-ssl-1.3.2.gem (100%)
    Fetching: railties-3.2.8.gem (100%)
    Fetching: rails-3.2.8.gem (100%)
    Successfully installed i18n-0.6.1
    Successfully installed activesupport-3.2.8
    Successfully installed builder-3.0.4
    Successfully installed activemodel-3.2.8
    Successfully installed rack-cache-1.2
    Successfully installed rack-test-0.6.2
    Successfully installed journey-1.0.4
    Successfully installed hike-1.2.1
    Successfully installed sprockets-2.1.3
    Successfully installed erubis-2.7.0
    Successfully installed actionpack-3.2.8
    Successfully installed arel-3.0.2
    Successfully installed tzinfo-0.3.34
    Successfully installed activerecord-3.2.8
    Successfully installed activeresource-3.2.8
    Successfully installed polyglot-0.3.3
    Successfully installed treetop-1.4.12
    Successfully installed mail-2.4.4
    Successfully installed actionmailer-3.2.8
    Successfully installed rack-ssl-1.3.2
    Successfully installed railties-3.2.8
    Successfully installed rails-3.2.8
    22 gems installed
    Installing ri documentation for i18n-0.6.1...
    Building YARD (yri) index for i18n-0.6.1...
    Installing ri documentation for activesupport-3.2.8...
    Building YARD (yri) index for activesupport-3.2.8...
    Installing ri documentation for builder-3.0.4...
    Building YARD (yri) index for builder-3.0.4...
    Installing ri documentation for activemodel-3.2.8...
    Building YARD (yri) index for activemodel-3.2.8...
    Installing ri documentation for rack-cache-1.2...
    Building YARD (yri) index for rack-cache-1.2...
    Installing ri documentation for rack-test-0.6.2...
    Building YARD (yri) index for rack-test-0.6.2...
    Installing ri documentation for journey-1.0.4...
    Building YARD (yri) index for journey-1.0.4...
    Installing ri documentation for hike-1.2.1...
    Building YARD (yri) index for hike-1.2.1...
    Installing ri documentation for sprockets-2.1.3...
    Building YARD (yri) index for sprockets-2.1.3...
    Installing ri documentation for erubis-2.7.0...
    Building YARD (yri) index for erubis-2.7.0...
    Installing ri documentation for actionpack-3.2.8...
    Building YARD (yri) index for actionpack-3.2.8...
    Installing ri documentation for arel-3.0.2...
    Building YARD (yri) index for arel-3.0.2...
    Installing ri documentation for tzinfo-0.3.34...
    Building YARD (yri) index for tzinfo-0.3.34...
    Installing ri documentation for activerecord-3.2.8...
    Building YARD (yri) index for activerecord-3.2.8...
    Installing ri documentation for activeresource-3.2.8...
    Building YARD (yri) index for activeresource-3.2.8...
    Installing ri documentation for polyglot-0.3.3...
    Building YARD (yri) index for polyglot-0.3.3...
    Installing ri documentation for treetop-1.4.12...
    Building YARD (yri) index for treetop-1.4.12...
    Installing ri documentation for mail-2.4.4...
    Building YARD (yri) index for mail-2.4.4...
    Installing ri documentation for actionmailer-3.2.8...
    Building YARD (yri) index for actionmailer-3.2.8...
    Installing ri documentation for rack-ssl-1.3.2...
    Building YARD (yri) index for rack-ssl-1.3.2...
    Installing ri documentation for railties-3.2.8...
    Building YARD (yri) index for railties-3.2.8...
    Installing ri documentation for rails-3.2.8...
    Building YARD (yri) index for rails-3.2.8...
    Installing RDoc documentation for i18n-0.6.1...
    Installing RDoc documentation for activesupport-3.2.8...
    Installing RDoc documentation for builder-3.0.4...
    Installing RDoc documentation for activemodel-3.2.8...
    Installing RDoc documentation for rack-cache-1.2...
    Installing RDoc documentation for rack-test-0.6.2...
    Installing RDoc documentation for journey-1.0.4...
    Installing RDoc documentation for hike-1.2.1...
    Installing RDoc documentation for sprockets-2.1.3...
    Installing RDoc documentation for erubis-2.7.0...
    Installing RDoc documentation for actionpack-3.2.8...
    Installing RDoc documentation for arel-3.0.2...
    Installing RDoc documentation for tzinfo-0.3.34...
    Installing RDoc documentation for activerecord-3.2.8...
    Installing RDoc documentation for activeresource-3.2.8...
    Installing RDoc documentation for polyglot-0.3.3...
    Installing RDoc documentation for treetop-1.4.12...
    Installing RDoc documentation for mail-2.4.4...
    Installing RDoc documentation for actionmailer-3.2.8...
    Installing RDoc documentation for rack-ssl-1.3.2...
    Installing RDoc documentation for railties-3.2.8...
    Installing RDoc documentation for rails-3.2.8...
    
    0 讨论(0)
  • 2020-12-05 04:55

    @Franco is correct: the "native extension" build scripts expect /usr/bin/gcc-4.2, which does not exist in OS X Mountain Lion.

    • If you upgraded to Mountain Lion from a prevoius OS X version, then you may already have gcc. In that case, just create a symlink to gcc: sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
    • If you have a fresh install of Mountain Lion, then you may not have gcc at all. In that case, you would need to install gcc as @Franco explains.

    This is not specifically a "rails" gem issue. Any gem that builds "native extensions" fails:

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. [...] You have to install development tools first.

    In my case, I was trying to install octopress, which depends on something called RedCloth.

    0 讨论(0)
  • 2020-12-05 04:55

    I ran into this issue as well, with Mountain Lion. The gem that was failing installation was json. To fix it, I installed the xcode CLI tools and then just symlinked the installed gcc (i686-apple-darwin11-llvm-gcc-4.2) as /usr/bin/gcc-4.2. Once this was done, it just worked.

    While trying to install another gem, I ran into a similar issue where the native build step complained about missing g++-4.2. I symlinked this exactly the same as I did with gcc-4.2 above, and it worked.

    UPDATE: OSX Mavericks with latest RVM

    With the latest OSX 10.9 and latest RVM, these issues seem to have gone away. So, time to upgrade.

    0 讨论(0)
  • 2020-12-05 05:04

    Try working through this first

    He assumes you already have homebrew. If you don't you can get it from here

    0 讨论(0)
提交回复
热议问题