"gem install mygem" does not install the gem
Hi,
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.
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Eric Hodel on 30 Jul, 2010 06:51 PM
Do you have a source code repository somewhere your gem?
If not, can you upload your completed gem?
3 Posted by Esen Sagynov on 02 Aug, 2010 05:08 AM
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 (http://www.cubrid.org/downloads). If not, I would be happy if you could point me to the reason why the gem cannot get installed properly.
Thank you drbrain!
Esen.
4 Posted by Esen Sagynov on 02 Aug, 2010 09:21 AM
It seems like I have accidentally removed the "s.extension" specification. That's why I guess the Gem didn't know what to build.
Support Staff 5 Posted by Eric Hodel on 02 Aug, 2010 08:34 PM
Ok, great!
Eric Hodel closed this discussion on 02 Aug, 2010 08:34 PM.
Esen Sagynov re-opened this discussion on 03 Aug, 2010 02:33 AM
6 Posted by Esen Sagynov on 03 Aug, 2010 02:33 AM
drbrain,
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?
Support Staff 7 Posted by Eric Hodel on 03 Aug, 2010 09:21 PM
You've probably configured sudo to strip unfamiliar environment variables. Try sudo -E.
8 Posted by Esen Sagynov on 04 Aug, 2010 01:15 AM
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:
-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!
Esen.
9 Posted by Esen Sagynov on 04 Aug, 2010 02:50 AM
I forgot to attach the mysql extconf.rb code. Here is it.
Support Staff 10 Posted by Nick Quaranto on 16 Aug, 2010 08:16 PM
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?
11 Posted by Esen Sagynov on 17 Aug, 2010 01:10 AM
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 ruby-forum.com
http://www.ruby-forum.com/topic/214260#new,
and in Google Groups for Ruby on Rails
http://groups.google.com/group/rubyonrails-talk/browse_thread/threa....
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.
Support Staff 12 Posted by Nick Quaranto on 31 Aug, 2010 01:16 AM
Cool, considering this resolved then.
Nick Quaranto closed this discussion on 31 Aug, 2010 01:16 AM.