This help site has been deprecated. Please send your requests to

"gem install mygem" does not install the gem

Esen Sagynov's Avatar

Esen Sagynov

30 Jul, 2010 09:13 AM


I am encountering an odd behavior of gem install function. Can anyone explain me what "gem install" actually does?

I have several C code and header files, and one extconf.rb file, + mygem.gemspec file. So, when I build a gem it successfully creates mygem-0.61.gem.

So, when I install it locally using "gem install mygem-0.61.gem" I expect the gem to create a makefile, because in the extconf.rb file I explicitly indicate it, and then "make install" that newly created Makefile. However, "gem install' does not create a Makefile and does not install it. What it does is just copies those several files to the gem directory, where Gem keeps all its gems.

What I have to do is manually rub "ruby extconf.rb", which creates the Makefile, and manually "make install".

The questions is: Should not "gem install" perform all these operation by itself, when I type "gem install mygem"?

Thank you in advance for your help.

  1. Support Staff 1 Posted by Eric Hodel on 30 Jul, 2010 06:51 PM

    Eric Hodel's Avatar

    Do you have a source code repository somewhere your gem?

    If not, can you upload your completed gem?

  2. 2 Posted by Esen Sagynov on 02 Aug, 2010 05:08 AM

    Esen Sagynov's Avatar

    Yes, I do have! But, let me upload here the latest code that I have built. I haven't updated the SVN as I cannot totally get it pushed. So, below is the attachment.

    There is one tricky thing for you. This gem is a Driver for CUBRID Database. Which means that you can install it (make and then install) if you have CUBRID installed, as there is a C API which it links to and the header files in its include directory.

    So, if you wish to test it directly, you are welcome to download the CUBRID installer ( If not, I would be happy if you could point me to the reason why the gem cannot get installed properly.

    Thank you drbrain!


  3. 3 Posted by Esen Sagynov on 02 Aug, 2010 09:21 AM

    Esen Sagynov's Avatar

    It seems like I have accidentally removed the "s.extension" specification. That's why I guess the Gem didn't know what to build.

  4. Support Staff 4 Posted by Eric Hodel on 02 Aug, 2010 08:34 PM

    Eric Hodel's Avatar

    Ok, great!

  5. Eric Hodel closed this discussion on 02 Aug, 2010 08:34 PM.

  6. Esen Sagynov re-opened this discussion on 03 Aug, 2010 02:33 AM

  7. 5 Posted by Esen Sagynov on 03 Aug, 2010 02:33 AM

    Esen Sagynov's Avatar


    In order to install the gem you have to run the command under the "sudo". However, some very weird behavior is happening with Ruby when I run the code with "sudo" command.

    Let's say I have the following code in "myex.rb" source file:

    if ENV["CUBRID"]
    puts "ENV[CUBRID] is: '#{ENV["CUBRID"]}'" else
    puts "$CUBRID_BROKER is not defined. Possibly you have not installed CUBRID Database yet." end

    I have installed the CUBRID Database, and when I run the code by typing "ruby myex.rb" I correctly receive the path where CUBRID has been installed:

    ENV[CUBRID] is: '/home/esen/programfiles/CUBRID'

    However, when I run this code with "sudo" at the beginning like "sudo ruby myex.rb", the "ENV['CUBRID']" is actually nil, thus, returns the second string in the else block.

    Am I doing something wrong?
    Could you please explain why "sudo" neglects all ENVironmental variables?

  8. Support Staff 6 Posted by Eric Hodel on 03 Aug, 2010 09:21 PM

    Eric Hodel's Avatar

    You've probably configured sudo to strip unfamiliar environment variables. Try sudo -E.

  9. 7 Posted by Esen Sagynov on 04 Aug, 2010 01:15 AM

    Esen Sagynov's Avatar

    I found the reason. Actually, by default Ubuntu is configured sudoer setting env_reset to ON, which means that when running sudo all non-system (safe) variables, including user paths, will be reset, that is cleared off. Only system variables and their save values will remain. There are several solutions:

    1. To set that env_reset to OFF, manually.
    2. Manually, set the necessary paths to the safe_path.
    3. Manually, add -E flag right after the sudo command and before the rest command "gem install....".
    4. Manually, create alias for sudo so that it always runs -E or safe_path together.

    -E was exactly what I did and it worked for me just fine. However, since I am building a gem for global users and don't want to make every one of them to type -E after the sudo in order to get my gem installed.

    I looked at other gems how they solve this problem, as I can install them without -E. For instance, I have attached the sample code found in mysql's extconf.rb file, which somehow deals with this problem as it also extracts ENV['PATH'] variable, just like me. But when installing mysql, I do not need to type -E.

    I saw in mysql's code it adds the -E flag to the cpp_command and prints it out to the "system", but somehow I cannot replicate it.

    Could you please look at the code and point me to the possible solution? I would be unbelievable grateful for your help! There should be some way to set this -E in runtime as if I added it manually.

    Any guide is highly appreciated.

    Thank you, drbrain, in advance!


  10. 8 Posted by Esen Sagynov on 04 Aug, 2010 02:50 AM

    Esen Sagynov's Avatar

    I forgot to attach the mysql extconf.rb code. Here is it.

  11. Support Staff 9 Posted by Nick Quaranto on 16 Aug, 2010 08:16 PM

    Nick Quaranto's Avatar

    Any update on this? I don't have too much experience with C extensions...maybe someone in #ruby-lang or #rubygems on IRC could help?

  12. 10 Posted by Esen Sagynov on 17 Aug, 2010 01:10 AM

    Esen Sagynov's Avatar

    Yeah, I found the temporary solution. The problem was in Linux Ubuntu "sudo" was reseting the ENVironmental variables like the PATH to CUBRID Database Server, which I need when installing the gem. So, I looked all over the internet posted at,
    and in Google Groups for Ruby on Rails

    Finally found a temp solution to use -E flag when running sudo like

    "sudo -E gem install cubrid"

    -E flag would give a notice to sudo not to reset the ENV variables.

    However, I am still curious how does mysql gem solve this issue, as it also addresses the EVN variables, but I do not need to use -E flag.

  13. Support Staff 11 Posted by Nick Quaranto on 31 Aug, 2010 01:16 AM

    Nick Quaranto's Avatar

    Cool, considering this resolved then.

  14. Nick Quaranto closed this discussion on 31 Aug, 2010 01:16 AM.

Discussions are closed to public comments.
If you need help with please start a new discussion.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

03 Dec, 2021 11:06 AM
02 Dec, 2021 09:41 AM
16 Nov, 2021 07:55 AM
05 Nov, 2021 07:09 AM
03 Nov, 2021 07:18 PM