Oct 18, 2014

Ruby-oci8 gem install fail !

Oracle & rails on a mac have a very estrange relation it gets exponentially annoying to setup a rails application with Oracle and the irritant here is the installation of Ruby-oci8 gem. 
This gem is not installed straight forward like any other gem, if you have already included the same in your Gemfile and tried bundle install you may get following error.


Installing ruby-oci8 (2.1.7)
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/akshatpaul/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for load library path...
  DYLD_LIBRARY_PATH is not set.
checking for cc... ok
checking for gcc... yes
checking for LP64... yes
checking for sys/types.h... yes
checking for ruby header... ok
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/akshatpaul/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
    --with-instant-client
    --without-instant-client
/Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:891:in `get_home': RuntimeError (RuntimeError)
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:707:in `initialize'
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `new'
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `get'
    from extconf.rb:18:in `<main>'
---------------------------------------------------
Error Message:
  Set the environment variable ORACLE_HOME if Oracle Full Client.
  Append the path of Oracle client libraries to DYLD_LIBRARY_PATH if Oracle Instant Client.
 
Backtrace:
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:891:in `get_home'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:707:in `initialize'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `new'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `get'
  extconf.rb:18:in `<main>'
---------------------------------------------------
See:
 * http://rubydoc.info/gems/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://rubydoc.info/gems/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://ruby-oci8.rubyforge.org/en/file.report-installation-issue.html to report an issue.


extconf failed, exit code 1

Gem files will remain installed in /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7 for inspection.
Results logged to /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/extensions/x86_64-darwin-12/2.0.0-static/ruby-oci8-2.1.7/gem_make.out

An error occurred while installing ruby-oci8 (2.1.7), and Bundler cannot continue.
Make sure that `gem install ruby-oci8 -v '2.1.7'` succeeds before bundling.


Next when you try installing the gem itself by executing gem install ruby-oci8 -v '2.1.7' or any version you will get stuck here : 

gem install ruby-oci8 -v '2.1.7'

akshatpaulsmbp2:pett akshatpaul$ gem install ruby-oci8 -v '2.1.7'
Building native extensions.  This could take a while...
/Users/akshatpaul/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/ext/builder.rb:73: warning: Insecure world writable dir /usr/local in PATH, mode 040777
ERROR:  Error installing ruby-oci8:
    ERROR: Failed to build gem native extension.

    /Users/akshatpaul/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for load library path...
  DYLD_LIBRARY_PATH is not set.
checking for cc... ok
checking for gcc... yes
checking for LP64... yes
checking for sys/types.h... yes
checking for ruby header... ok
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/akshatpaul/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
    --with-instant-client
    --without-instant-client
/Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:891:in `get_home': RuntimeError (RuntimeError)
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:707:in `initialize'
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `new'
    from /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `get'
    from extconf.rb:18:in `<main>'
---------------------------------------------------
Error Message:
  Set the environment variable ORACLE_HOME if Oracle Full Client.
  Append the path of Oracle client libraries to DYLD_LIBRARY_PATH if Oracle Instant Client.
 
Backtrace:
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:891:in `get_home'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:707:in `initialize'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `new'
  /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in `get'
  extconf.rb:18:in `<main>'
---------------------------------------------------
See:
 * http://rubydoc.info/gems/ruby-oci8/file/docs/install-full-client.md for Oracle full client
 * http://rubydoc.info/gems/ruby-oci8/file/docs/install-instant-client.md for Oracle instant client
 * http://ruby-oci8.rubyforge.org/en/file.report-installation-issue.html to report an issue.


extconf failed, exit code 1

Gem files will remain installed in /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/gems/ruby-oci8-2.1.7 for inspection.
Results logged to /Users/akshatpaul/.rvm/gems/ruby-2.0.0-p247/extensions/x86_64-darwin-12/2.0.0-static/ruby-oci8-2.1.7/gem_make.out

No problem, now lets install ruby-oci8 the right way ;)
Simply follow following steps in order and you will be done :

Step 1 
Go to oracle web site for some downloads http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html.

Step 2
Download the 64bit versions of instantclient-sqlplus, instantclient-sdk, instantclient-basic - the 32bit versions do not work with OSX 10.92.
Note : Please download 64bit version only as 32bit just wont work on your OS 10.8+ version. Also you would require oracle login credentials to download this free stuff.

Step 3
Create directories at /opt/oracle incase its not yet created with following command:
$ mkdir /opt/oracle

Step 4
Unzip instantclient-basic, move to /opt/oracle the unzipped folder will be something like instantclient_11_2.
Note : we will be moving other two unzipped folders in this folder, wont keep them separately.

Step 5
Next unzip instantclient-sqlplus move its filed & folders to /opt/oracle/instantclient_11_2/

Step 6 
Next unzip instantclient-sdk move its contents /opt/oracle/instantclient_11_2/

Step 7
Next, via terminal we will add some env variable. First, DYLD_LIBRARY_PATH=/opt/oracle/instantclient_11_2 export DYLD_LIBRARY_PATH

Secondly, ORACLE_HOME=/opt/oracle/instantclient_11_2 export ORACLE_HOME

Check if env variables are created properly by executing $ env

Step 8 
Now we will create a sym link. Go to instantclient_11_2/ by executing cd /opt/oracle/instantclient_11_2.
run $ ln -s libclntsh.dylib.11.1 libclntsh.dylib

Step 9
Now run gem install ruby-oci8



Apr 27, 2012

Ad-Hoc distribution - Apple's Best Kept Secret (with Rhomobile)


Ad-Hoc distribution is certainly something which helps you scale the testing of your iOS application with apple letting you broadcast your app for 100 unique devices. But just as everything’s very controlled in an iOS environment, ad-hoc application distribution is bureaucratically confusing- unless we go through apples 500+ pages developers manual.

In this post as my other posts there special mention for Rhomobile apps. In case you’re not creating a rhomobile/Rhodes app plz skipt those steps beginning with Rhodes.

Lets Begin

Step 1 : Before you begin, you must be registered ios developer at developer.apple.com. Also, your developer certificate, distribution certificate should be added in the keychain.


Step 2 : In your apple ios development profile at developer.apple.com make a new provisional profile in distribution and choose ad-hoc in that. Also, select all the devices on which the application will be installed (max upto 100 devices).

Step 3 : Download the same and load it in xcode.

Step 4 : For Rhodes app – You can see all the details of the profile which we will later use in your Rhodes application’s build.yml by clicking organizer in the right side of xcode.

Step 5: For Rhodes app – following details will need to be filled in build.yml. Lets take an example :

iphone: 
  provisionprofile: xx32xx42-Axx1-xxCx-xxxx-xQWxERxTYxxU
  sdk: iphoneos5.0
  codesignidentity: "iPhone Distribution: your company name"
  entitlements: ""
  configuration: Release
  BundleIdentifier: com.companyname.appname
  BundleURLScheme: app_name_type

Now let’s map what is above in these yml settings to what you see in your xcode organizer:

Provisionprofile : this is the Provisional identifier
Sdk : this is just the sdk version
Code signidentiy : add your common name from distribution certificate from keychain.
Entitlements : just leave it blank
Configuration : has to be release for ad-hoc.
Buncleidentifier : you can see this as app identifier but there is a long code before this in organizer u can ignore the long code and simply take com(which is default)[dot]distribution_name[dot]application_name
BundleURL scheme : just name your app


Step 6 : For Rhodes app - Now what lets load your Rhodes application in xcode by following two steps :  http://docs.rhomobile.com/rhodes/build
$ rake switch_app
$ rake build:iphone:setup_xcode_project

This will create a xcode project in the Rhodes source code folder. Which you can see from your build.yml. Navigate to the /platform/iphone folder and open rrhorunner.xcodeproj. This will open your Rhodes application in Xcode.
for more information on ios build with rhomobile, plz check ios build section at Rhomobile Docs.

Step 7 : Create a new configuration in your Project Settings
 I am not describing here how to create info.plist file which is no longer required in case of xcode4, but definetly is necessary for testflight (I’ll try to include that later in this post). Create an Ad Hoc Distribution configuration. Click on your project in the Groups & Files pane and then select your project in the column that shows your project and targets.




If you are not already on the Info screen, click the Info tab. Next click the ‘+’ button and select Duplicate “Release” Configuration.




Give the new configuration a name, preferably ad-hoc so that you remember it :P





Setup 8 : Setting up Target
Select your Target (below your Project), click on code signing identity property and select “don’t code sign”. Also select default iPhone Distribution for Ad-Hoc distribution and iPhone developer for debug, development and release.



Step 9 : Setting up archive scheme
From the drop down menu in your tool bar next to the Run and Stop button, select Edit Scheme. Select Archive in the left pane and then set the Build Configuration to your Ad Hoc Distribution and click OK.



Step 10 : Yes its almost done !
From the top menu select Product and then click archive, your application build will be created.

Step 11 : Create installable ipa and share J.
After build is created successfully, organizer will open automatically to create the IPA file, with the archive highlighted, click the Share button and then confirm the provisioning profile you want to use. If you only have the one distribution provisioning profile it should default to the correct one. Click Next and then give the IPA file a name and save it.



Step 12 : To distribute your .ipa simply attach the file and mail it. Double click the ipa file loads it into itune, sync your itune and your application is installed on your device.


And its done !!!