Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify compiler for "gem install"?

Tags:

rubygems

How can I specify which compiler should be used for gem install? In Bash

CC=gcc gem install ...

does not help, because it still uses Solaris Studio on my system.

like image 985
Alex Avatar asked Dec 29 '10 14:12

Alex


People also ask

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

What is gem install command?

The install command installs local or remote gem into a gem repository. For gems with executables ruby installs a wrapper file into the executable directory by default. This can be overridden with the –no-wrappers option.


1 Answers

For sqlite3-ruby your method is supported since Jan 2011 commit. But in general it's not possible to override this because of how rubygems works. It

  1. Unpacks the gem.

  2. Looks into it spec & discovers that it uses 'extensions' attribute--usually a path to a specially written extconf.rb file.

  3. Runs that file to generate a Makefile. Unless author of extconf.rb explicitly said to honor env variables, they are ignored. For example, in latest versions of sqlite3-ruby gem, its extconf.rb has a line

    RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
    

    So if you run in Bash

    CC=gcc gem install sqlite3-ruby
    

    extconf.rb will generate the Makefile with the variable CC in it that is set to gcc or whatever you want.

  4. After Makefile is generated, rubygems executes make utility to compile the extension.

Theoretically, if rubygems allowed us to specify additional command line parameters for make, we could use its -e option and then do not depend on authors of extconf.rb at all. (-e option gives variables taken from the environment precedence over variables from makefiles.)

like image 115
Alexander Gromnitsky Avatar answered Oct 27 '22 14:10

Alexander Gromnitsky