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 

Error when installing Rubocop globally on Macos using rbenv and homebrew

To use the Rubocop gem with VSCode to assist with code linting, it’s sometimes desirable to have Rubocop installed at the system level. I recently ran into a permissions problem when using the homebrew version of Ruby to install Rubocop, and this was the solution:

➜ gem install rubocop
ERROR: While executing gem … (Gem::FilePermissionError)
You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
➜ rbenv install -l
➜ rbenv install 3.0.2
➜ rbenv global 3.0.2
➜ ruby --version

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
➜ gem install rubocop

(long pause)

Done installing documentation for unicode-display_width, ruby-progressbar, ast, parser, rubocop-ast, regexp_parser, rainbow, parallel, rubocop after 24 seconds
9 gems installed

Fix slow rspec on macOS – 10x speedup

For some reason rspec was running horribly slow on my macOS laptop, with a simple test suite taking over 30 seconds to run. This made TDD almost unbearable:

>rspec spec/features
...
Finished in 27.29 seconds (files took 33.71 seconds to load)
8 examples, 2 failures

After some googling, the recommended approach is to compile spring binstubs for rspec. For good hygiene, we’ll use bundler to do this, and use guard so we can leave a terminal window open on a second monitor and see test results automatically after saving code changes.

# edit /Gemfile
group :development do
gem 'guard'
gem 'guard-rspec'
gem 'spring'
gem 'spring-commands-rspec'
gem 'spring-watcher-listen'
end

>bundle install --path vendor/bundle --without=production --binstubs # install gems into vendor/bundle
>echo 'vendor/bundle' >> .gitignore # don't track installed gemfiles

Update 16/08/2020: I no longer install gems into ./vendor/bundle and instead let rbenv handle the location for me. I don’t believe this change in approach affects the meat of this article.

Now replace the bundler rails binstubs with updated rails gem versions and insert spring:

>bundle exec rails app:update:bin # now regenerate standard rails binstubs
>bin/rails app:update:bin # norly plox use teh rail binstubs
>bundle exec spring binstub --all # use spring versions of binstubs
>bundle exec guard init # create guard config file /Guardfile

Note: bin/rails can get overwritten by bundler and stop accepting commands eg “bin/rails server” will show the default output of “rails” instead of launching the server. This can be fixed by running “bundle binstubs railties” then updating the binstubs again as per the instructions above.

Running “bundle config –delete bin” will stop bundler from blatting bin/rails but this also means you will need to manually generate binstubs using eg “bundle binstubs cucumber”.

Note also that bundler pulls in config from $APP/.bundle/config and ~/.bundle.config, so disabling binstubs in your app folder can be overridden by your home directory config.

# edit /Guardfile
guard :rspec, cmd: “bundle exec bin/rspec”, failed_mode: :keep do

>bundle exec guard


Finished in 1.72 seconds (files took 3.17 seconds to load)
5 examples, 2 failures

From 33 seconds to 3 seconds. Nice!

Tip: now instead of using “bundle exec” rails or rake, use bin/$GEMNAME eg “bin/rails console”. The spring server running in the background will respond much faster than booting rails each time.