Install ruby-oci8 Gem on Debian based Linux system

These are the steps to install ruby-oci8 Gem on Ubuntu. 

Step 1: Download the basic & sdk instantclient zip files from https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html 

instantclient-basic-linux.x64-21.8.0.0.0dbru.zip 
instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip 
  

Step 2: Install following packages 

sudo apt-get install build-essential 
sudo apt-get install libaio-dev 
  

Step 3: Create a folder oracle inside /opt/ 

mkdir /opt/oracle 
  

Step 4: Go to inside /opt/oracle/ 

cd /opt/oracle 
  

Step 5: Place the basic instantclient folder inside /opt/oracle 

sudo cp ~/Downloads/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip /opt/oracle/ 
  

Step 6: Place the sdk instantclient folder inside /opt/oracle 

sudo cp ~/Downloads/instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip /opt/oracle/ 
  

Step 7: Unzip the basic instantclient folder 

sudo unzip instantclient-basic-linux.x64-21.8.0.0.0dbru.zip 
  

Step 8: Unzip the sdk instantclient folder 

sudo unzip instantclient-sdk-linux.x64-21.8.0.0.0dbru.zip 
  

Step 9: Check the folders inside /opt/oracle/. It should now have a folder named as instantclient_21_8 

Step 10: Update the runtime link path 

sudo sh -c “echo /opt/oracle/instantclient_21_8 > \ 
>      /etc/ld.so.conf.d/oracle-instantclient.conf”  
  

Step 11: Check the runtime link path, It should now return /opt/oracle/instantclient_21_8 

cat /etc/ld.so.conf.d/oracle-instantclient.conf 
  

Step 12: Set the path in env 

export LD_LIBRARY_PATH=/opt/oracle/instantclient_21_8:$LD_LIBRARY_PATH 
  

Step 13: Check the path if set properly in env. It should now have proper value set as LD_LIBRARY_PATH=/opt/oracle/instantclient_21_2:/opt/instantclient 

env | grep LD_LIBRARY_PATH 
  

Step 14: Now try by installing the gem ruby-oci8 

gem install ruby-oci8s 
  

It should work now. 

Alternate Install 

These steps take you through the instant client installation process as well, just to provide some context. Download the instant and SDK zip files here: 

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html 

Unzip both files in the following directory as root. 

/opt/oracle 

Enter the instantclient_12_2 directory following the unzip and create a symlink for the libclntsh.so file: 

ln -s libclntsh.so.12.1 libclntsh.so 
 

Now, depending on your OS, you’ll need to update your LD_LIBRARY_PATH location. In Ubuntu, do the following: 

sudo nano /etc/ld.so.conf.d/moreLibs.conf 
 

And enter the following in the file and save 

/opt/oracle/instantclient_12_2 
 

Now run the following command: 

sudo ldconfig 
 

And rerun your gem install:

gem install ruby-oci8 

Rails: bundler can’t install gem ruby-oci8

The Solution

brew tap InstantClientTap/instantclient
brew install instantclient-basic
brew install instantclient-sqlplus
brew install instantclient-sdk

Sourced from: https://stackoverflow.com/a/65320336

The Error

➜ bundle install

Error Message:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.
"oci.h" could not be found in: /usr/local/lib/sdk/include
An error occurred while installing ruby-oci8 (2.2.12), and Bundler cannot continue.

Rails and Passenger app deployment error: rake-13.0.6 Bundler::GemNotFound

Note that the server paths to Apache, Ruby, and your app web folder will vary depending on your operating system and server configuration.

After deploying a Rails app to a server environment via Capistrano, the following generic Phusion Passenger error screen is being shown:

I ssh to the server and check the Apache logs for errors:

➜ tail -f /etc/httpd/logs/error_log
...
App 29384 output: Error: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:91:in `block in materialize'
...

I note that Bundler is looking for a Gem in /opt/ruby-2.5, however the app’s ./.ruby-version is set to 2.7.4.

My hunch is that the Passenger configuration is set to an old version of Ruby, which has missing dependencies. In a way the missing deps error is lucky, because otherwise the app would be running on an outdated Ruby version compared to dev.

To validate my theory, I check the Passenger config for my app.

➜ ssh [email protected]
➜ sudo su
➜ ls /etc/httpd/conf.d/vhost
...
my-app-name-int.conf my-app-name-uat.conf
...

After identifying the correct config file, I check the contents. Sure enough, the Ruby version is set incorrectly to 2.5:

➜ cat /etc/httpd/conf.d/vhost/my-app-name-uat.conf
...
PassengerRuby /opt/ruby-2.5/bin/ruby
...

I backup the config file, then update the Ruby version to be correct:

➜ cp /etc/httpd/conf.d/vhost/my-app-name-uat.conf /etc/httpd/conf.d/vhost/my-app-name-uat.conf.bak # backup the current configuration
➜ vim /etc/httpd/conf.d/vhost/my-app-name-uat.conf # edit the current config
...
# PassengerRuby /opt/ruby-2.5/bin/ruby
PassengerRuby /opt/ruby-2.7/bin/ruby
...
➜ service httpd reload # reload Apache to apply the changes

# ➜ apachectl restart # if Apache issues encountered, restart Apache

Note: if PassengerRuby is already correct here, the Ruby version might still be missing gems – continue to the next steps

Finally, I manually install the missing Ruby deps. Note: these commands are run using the appropriate app service account, not root.

➜ cd /var/www/my-app-name-uat/current
➜ export PATH=/opt/ruby-2.7/bin:$PATH
➜ bundle install

Passenger now successfully launches my app when the url is visited in a web browser.

Note that this complete update process must be done on each server node if using a load balanced group.

If further bundler errors are encountered, the system gems might need to be updated:

PATH=/opt/ruby-2.7/bin:$PATH gem update --system

Note: make sure to to include the –system flag here, otherwise other apps on the server might be impacted.

Full Error Trace

➜ tail -f /etc/httpd/logs/error_log

App 29384 output: [passenger_native_support.so] not found for current Ruby interpreter.
App 29384 output: This library provides various optimized routines that make
App 29384 output: Phusion Passenger faster. Please run 'sudo yum install passenger-devel-6.0.7'
App 29384 output: so that Phusion Passenger can compile one on the next run.
App 29384 output: [passenger_native_support.so] not downloading because PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0
App 29384 output: [passenger_native_support.so] will not be used (can't compile or download)
App 29384 output: --> Passenger will still operate normally.
App 29384 output: Error: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:91:in block in materialize' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:85:inmap!'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:85:in materialize' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:170:inspecs'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:237:in specs_for' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:226:inrequested_specs'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:108:in block in definition_method' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:20:insetup'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler.rb:107:in setup' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/setup.rb:20:in'
App 29384 output: /opt/ruby-2.5/lib64/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in require' App 29384 output: /opt/ruby-2.5/lib64/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:inrequire'
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:365:in activate_gem' App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:221:inblock in run_load_path_setup_code'
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:529:in running_bundler' App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:220:inrun_load_path_setup_code'
App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:91:in preload_app' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:189:inblock in '
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:382:in run_block_and_record_step_progress' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in'
App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in <module:PhusionPassenger>' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in'
[ E 2022-08-02 17:37:44.7235 2524/T8h age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/my-app-name/current: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
Error ID: 60047415
Error details saved to: /tmp/passenger-error-DEwgnV.html

[ E 2022-08-02 17:37:44.7526 2524/Te age/Cor/Con/CheckoutSession.cpp:276 ]: [Client 4-2281] Cannot checkout session because a spawning error occurred. The identifier of the error is 60047415. Please see earlier logs for details about the error.

Rails and WebPacker: SSL_connect error

When implementing SSO for a legacy Rails 5 application with a Puma dev environment, I encountered an issue with JavaScript content not loading on some pages. The server output the following error message:

➜ bundle exec rails s -b "ssl://localhost:3000?key=config/cert.key&cert=config/cert.crt"
=> Booting Puma
=> Rails 5.2.8.10 LTS application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 2.7.4-p191) ("Birdie's Version")
...
Started GET "/" for 127.0.0.1 at 2022-06-21 17:07:43 +1000
...
2022-06-21 17:17:21 +1000 Rack app ("GET /packs/js/form-2c133051829ab02ebb74.js" - (127.0.0.1)): #<OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: wrong version number>

The Fix

It looks like the local dev environment had previously been run under HTTP, not HTTPS. Updating the webpacker config and restarting the server resolved the issue:

➜ vim config/webpacker.yml
...
development:
  <<: *default
  compile: true
  warnings: true

  dev_server:
    host: localhost
    port: 3035
    hmr: false
    https: false # <-- set this to true
...

➜ ./bin/webpack-dev-server

Rails: Python2 error on yarn install

I recently worked on a legacy codebase that requires Python2, which has been deprecated for some time and is no longer available via homebrew.

Using this Stack Overflow thread I was able to resolve the issue as below. Note that the “pyenv global” command might interfere with with your Python3 environment.

The Error

➜ yarn install --check-files
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2

➜ which python
python not found

➜ which python2
python2 not found

The Fix

➜ brew install pyenv
➜ pyenv install 2.7.18
➜ pyenv global 2.7.18
➜ PATH=$(pyenv root)/shims:$PATH
➜ which python2
/Users/user/.pyenv/shims/python2

➜ yarn install --check-files
yarn install v1.22.19
...
Done in 10.26s

Add to ~/.bashrc or ~/.zshrc to make available in future shell sessions:

# make python exe available globally
PATH=$(pyenv root)/shims:$PATH

Rails: Puma MiniSSL::SSLError

The problem

When setting up a dev environment for older Rails projects, Puma can sometimes have trouble serving https:// pages. Puma boots ok but will begin choking with a MiniSSL::SSLError:

➜ bundle exec rails s -b "ssl://0.0.0.0:3000?key=config/ssl.key&cert=config/ssl.crt"
=> Booting Puma
=> Rails 6.0.4.1 application starting in development

2022-03-03 17:19:21 +1100: SSL error, peer: 127.0.0.1, peer cert: , # <Puma::MiniSSL::SSLError: OpenSSL error: error:141F7065:SSL routines:final_key_share:no suitable key share - 337604709>

The fix

This error is caused by a bug in older versions of Puma. To fix, simply update the version of Puma in the Rails gemfile:

/Gemfile
#gem 'puma', '~> 3.11'
gem 'puma', '~> 4.3.8'

Then install the new version of the Puma gem and test:

➜ bundle install
➜ bundle exec rails s -b "ssl://0.0.0.0:3000?key=config/ssl.key&cert=config/ssl.crt"
=> Booting Puma
=> Rails 6.0.4.1 application starting in development

Puma should now run and serve https pages successfully.

Rails 6 & Node: Yarn error on install around ‘remove_cv_t’

This error can occur when setting up a development environment for an existing Rails 6 project and the node dependencies are being installed. It seems to be caused by an incompatibility between node-sass and Node 16.

Here are step by step instructions on how to fix the problem by specifying the version of node to use in the project folder using NVM.

➜ bundle exec rails server # rails won't boot, yarn error
...
========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================

➜ yarn install --check-files # yarn install fails...
...
/Users/user/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?

➜ brew install nvm # install Node Version Mgr if needed
➜ echo "14.18.2" > .nvmrc # create a version file for NVM (do this in your rails project directory)
➜ cat .nvmrc
14.18.2

➜ node -v # check the current node version
v16.13.1

➜ nvm use
Found '/Users/user/project/.nvmrc' with version <14.18.2>
Now using node v14.18.2 (npm v6.14.15)

➜ node -v # verify we're now using the correct node version
v14.18.2

➜ yarn install --check-files # install should now complete ok
...
✨  Done in 8.73s.

➜ bundle exec rails server # rails should now boot
=> Booting Puma

Here’s the full error trace:

In file included from /Users/user/.node-gyp/16.13.1/include/node/v8.h:30:
/Users/user/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:710:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/user/project/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 21.2.0
gyp ERR! command "/Users/user/.nvm/versions/node/v16.13.1/bin/node" "/Users/user/project/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/user/project/node_modules/node-sass
gyp ERR! node -v v16.13.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

RSpec error – Host header or origin header is specified and is not whitelisted or localhost.

I encountered the following head-scratcher when trying to run the following RSpec test on MacOs:

➜ bundle exec rspec ./spec/features/some_spec.rb:12
...

Capybara starting Puma…
Version 4.3.8 , codename: Mysterious Traveller
Min threads: 0, max threads: 4
Listening on tcp://127.0.0.1:63422
...

Selenium::WebDriver::Error::WebDriverError:
unexpected response, code=500, content-type="text/html"
Host header or origin header is specified and is not whitelisted or localhost.


After much fruitless poking around in ./spec/rails_helper.rb, I checked my /etc/hosts file and realised I had mapped 127.0.0.1 to a custom name. I updated /etc/hosts to include only the following lines:

127.0.0.1 localhost
0.0.0.0 my.localdev


And hey presto, Selenium would now run the rest of my (still failing) tests.

As an aside, I tried passing the options '--headless', '--disable-web-security', '-–allow-file-access-from-files', '--allowed-origins=*‘ to Capybara in ./spec/rails_helper.rb, and none seemed to have any effect.

Rails HTTPs error on localhost – getaddrinfo SocketError

I recently began developing a Rails Plugin gem, and running the dummy app locally using HTTP worked flawlessly out of the box. However, when it came time to test HTTPS, I encountered the following error:

➜ rails s -b "ssl://0.0.0.0:3000?key=config/cert.key&cert=config/cert.crt"
=> Booting WEBrick
=> Rails 5.2.6 application starting in development on http://ssl://0.0.0.0:3000?key=config/cert.key&cert=config/cert.crt:3000
=> Run rails server -h for more startup options
INFO WEBrick 1.4.4
`getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)

This was puzzling at first as I had other apps running fine using HTTPS. After closer inspection I discovered the other apps were running under the Puma webserver, while my gem had defaulted to using WEBrick.

Solution

The solution was to find the latest version of Puma and add it to my gem:

➜ gem search puma
*** REMOTE GEMS ***
...
puma (5.5.2 ruby java java, 5.4.0, 4.3.10)
...

edit ./Gemfile:
...
gem "puma", "5.5.2"
...

Install the gem:

➜ bundle install
...
Installing puma 5.5.2 with native extensions
...

The Rails app then booted into HTTPs successfully under Puma:

➜ rails s -b "ssl://0.0.0.0:3000?key=config/cert.key&cert=config/cert.crt"
=> Booting Puma
...
Listening on ssl://0.0.0.0:3000?key=config/cert.key&cert=config/cert.crt


Rails: Error installing gem mysql2 on MacOs

When installing gems on a new project under MacOs using bundler, I encountered the following error for MySql:

Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

It seems the clang compiler couldn’t find an SSL library on the system. The solution was:

> brew install openssl
> bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)
> bundle

# This also works:
> export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/