13

As a background, here's my environment:

vishal@dishDell:~$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.24
  - RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.9.1
     - /home/vishal/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

This is what happens when I try running gem install rails.

vishal@dishDell:~$ sudo gem install rails
[sudo] password for vishal: 
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/json-1.7.3 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/json-1.7.3/ext/json/ext/parser/gem_make.out

I installed Ruby 1.9.3 using apt-get, and I installed RubyGems from a tarball at rubygems.org. What should I do to get this to work?

Vishal Kotcherlakota
  • 1,134
  • 4
  • 13
  • 36

2 Answers2

18

this worked for me with Ubuntu 12.10:

sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo apt-get install rubygems
sudo gem install rails
Michael Bylstra
  • 5,042
  • 4
  • 28
  • 24
  • Interesting. Were you using the standard repositories? – Vishal Kotcherlakota Oct 27 '12 at 20:09
  • yes. RVM does sound like the better way of setting up rails for more experienced users. But for total Rails beginners (like myself) you would expect to be able to install rails in three lines: apt-get install ruby, apt-get install rubygems, gem install rails. I'm not sure why rubygems doesn't automatically install ruby-dev – Michael Bylstra Oct 28 '12 at 00:04
  • The repos were a little messed up in 12.04, that's why I was having issues. Glad to see that they fixed it! – Vishal Kotcherlakota Oct 28 '12 at 05:14
9

As pointed out in this other Stackoverflow question, check if you have ruby-1.9-dev or ruby-1.9.3-dev package. Install it if missing and then try install rails.

Also, have a look at RVM to install and manage multiple ruby versions at the same time.

Community
  • 1
  • 1
Kulbir Saini
  • 3,926
  • 1
  • 26
  • 34
  • 1
    I ended up removing my ruby and rubygems installations, and just did everything via RVM...it was much easier than I expected. Lesson learned: don't trust Ubuntu's repositories blindly! – Vishal Kotcherlakota Jul 16 '12 at 19:58