postmodern / chruby

Changes the current Ruby
MIT License
2.85k stars 190 forks source link

problem installing rails ....missing ruby.h #349

Closed dec1 closed 8 years ago

dec1 commented 8 years ago

I have a problem installing a custom version of rails. Im using opensuse 13.2 (which has a system ruby 2.1 already installed) I installed “ruby-install” and “chruby” so that I could install and manage custom ruby/rails versions without affecting the system ones. Installing ruby 2.2.3 itself seemed to work fine. However when I try to install rails via gem, I get an error. Somehow the installation seems to be looking for files belonging to the system (2.1) ruby instead of the (active) 2.2.3.

    declan@linux-p8rr:~> chruby system
    declan@linux-p8rr:~> ruby --version
    ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux-gnu]
    declan@linux-p8rr:~> 
    declan@linux-p8rr:~> 
    declan@linux-p8rr:~> chruby 2.2.3
    declan@linux-p8rr:~> ruby --version
    ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
    declan@linux-p8rr:~> 
    declan@linux-p8rr:~> 
    declan@linux-p8rr:~> gem install rubygems-update
    Successfully installed rubygems-update-2.4.8
    Parsing documentation for rubygems-update-2.4.8
    Done installing documentation for rubygems-update after 0 seconds
    1 gem installed
    declan@linux-p8rr:~> 
    declan@linux-p8rr:~> sudo gem install rails
    Building native extensions.  This could take a while...
    ERROR:  Error installing rails:
            ERROR: Failed to build gem native extension.

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

I can install “ruby-devel” via yast (my system package manager) but it shows version 2.1

I don’t feel too comfortable with this since it corresponds to my system ruby version and not the custom one I installed (2.2.3)

If I nonetheless do so I can then install “nokogiri” manually (Workaround for problem with libxml libraries .. see http://stackoverflow.com/questions/29782968/how-to-gem-install-nokogiri-use-system-libraries-via-gemfile http://stackoverflow.com/questions/24251494/nokogiri-gem-installation-error)

> sudo gem install nokogiri -- --use-system-libraries

Then finish rails installation

declan@linux-p8rr:~> sudo gem install rails
Successfully installed rails-4.2.4

Seems to have worked but, I cant seem to find rails then…

declan@linux-p8rr:~> gem list 

*** LOCAL GEMS ***

bigdecimal (1.2.6)
io-console (0.4.3)
json (1.8.1)
minitest (5.4.3)
power_assert (0.2.2)
psych (2.0.8)
rake (10.4.2)
rdoc (4.2.0)
rubygems-update (2.4.8)
test-unit (3.0.8)

Maybe I have to build ruby from source (should have the correct version of the headers then) and then tell “chruby” about it?

Any other ideas?

Any suggestions? Thanks in Advance. Declan

dec1 commented 8 years ago

P.S If I do the same with rvm instead of ruby-install & chruby rails is available afterwards .. ie seems to have been correctly installed

dec1 commented 8 years ago

Seems to work fine if I do the following:

(1) Build ruby from source (2) tell chruby about my custom ruby Note: its not very elegant to have to edit the chruby.sh file for this (RUBIES=() otherwise overwrites any env vars instead of adding to them! .. possible improvement?) (3) Manually install nokogiri using sys libs (wont work otherwise)

gem install nokogiri -- --use-system-libraries 

(4) chruby 2.2.3

(5)gem install ruby

things seem to work fine. rails gets built without errors and is available on the command line

rails  --version

Rails 4.2.4

So maybe theres something that needs to be improved in ruby-install instead?

postmodern commented 8 years ago

sudo does not inherit your current environment (specifically $PATH) for security reasons. Please try gem install rails without sudo.

danogwok commented 8 years ago

make sure you have

ruby-devel
installed.

ellcs commented 6 years ago

In case someone struggles with OpenSuse:

# ruby 2.1.x
zypper in gcc make ruby2.1-devel ruby2.1-devel-extra
# or ruby 2.2.x
zypper in gcc make ruby2.2-devel ruby2.2-devel-extra