Skip to content

Instantly share code, notes, and snippets.

@hogihung
Created November 11, 2014 13:05
Show Gist options
  • Select an option

  • Save hogihung/5ec9c25a5d76566241e7 to your computer and use it in GitHub Desktop.

Select an option

Save hogihung/5ec9c25a5d76566241e7 to your computer and use it in GitHub Desktop.
Installing Oracle Client on CentOS, with Ruby support
[username@hostname Downloads]$ ls -l
total 67196
-rw-rw-r-- 1 username username 67349889 Aug 19 19:37 oracle-instantclient12.1-basic-12.1.0.1.0-1.i386.rpm
-rw-rw-r-- 1 username username 629474 Aug 19 19:37 oracle-instantclient12.1-devel-12.1.0.1.0-1.i386.rpm
-rw-rw-r-- 1 username username 824523 Aug 19 19:36 oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.i386.rpm
[username@hostname Downloads]$ sudo rpm -i oracle-instantclient12.1-basic-12.1.0.1.0-1.i386.rpm
[sudo] password for username:
[username@hostname Downloads]$ sudo rpm -i oracle-instantclient12.1-devel-12.1.0.1.0-1.i386.rpm
[username@hostname Downloads]$ sudo rpm -i oracle-instantclient12.1-sqlplus-12.1.0.1.0-1.i386.rpm
[username@hostname Downloads]$ sqlplus
sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
[username@hostname Downloads]$ ls -l /usr/lib/oracle/
total 4
drwxr-xr-x 3 root root 4096 Aug 20 07:35 12.1
[username@hostname Downloads]$ ls -l /usr/lib/oracle/12.1/client/
total 8
drwxr-xr-x 2 root root 4096 Aug 20 07:36 bin
drwxr-xr-x 2 root root 4096 Aug 20 07:36 lib
[username@hostname Downloads]$ export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client/lib/:$LD_LIBRARY_PATH
[username@hostname Downloads]$ sqlplus
SQL*Plus: Release 12.1.0.1.0 Production on Wed Aug 20 07:57:33 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter user-name:
[username@hostname Downloads]$
[username@hostname Downloads]$ echo $ORACLE_HOME
[username@hostname Downloads]$ cd ..
[username@hostname ~]$ touch tnsnames.ora
[username@hostname ~]$ touch .oracle_client
[username@hostname ~]$ vim tnsnames.ora
[username@hostname ~]$ vim .oracle_client
[username@hostname ~]$ vim .oracle_client
[username@hostname ~]$ cat .oracle_client
[username@hostname ~]$ cat tnsnames.ora
rubyrailssvr =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = XE))
)
rubyrailssvr.homenet.com =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = XE))
)
[username@hostname ~]$
[username@hostname ~]$ cat .oracle_client
export ORACLE_BASE=/usr/lib/oracle
export ORACLE_HOME=$ORACLE_BASE/12.1/client
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=/home/username
[username@hostname ~]
[username@hostname ~]$ vim .oracle_client
[username@hostname ~]$ source ~/.oracle_client
[username@hostname ~]$ echo $ORACLE_BASE
/usr/lib/oracle
[username@hostname ~]$ echo $ORACLE_HOME
/usr/lib/oracle/12.1/client
[username@hostname ~]$ echo $LD_LIBRARY_PATH
/usr/lib/oracle/12.1/client/lib
[username@hostname ~]$ sqlplus railstest@rubyrailssvr
SQL*Plus: Release 12.1.0.1.0 Production on Wed Aug 20 08:31:42 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Enter password:
[username@hostname ~]$
IF YOU GET THE ERROR: ORA-21561 - OID generation failed, then you will need to make a minor update to the /etc/hosts file. You need to add the proper hostname of your client computer. See below:
[username@hostname ~]$ hostname
hostname
[username@hostname ~]$
[username@hostname ~]$ sudo vim /etc/hosts
[sudo] password for username:
127.0.0.1 localhost hostname localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.14 rubyrailssvr.homenet.com
[username@hostname ~]$
NOTE: The last entry, the 192.168.1.14, is optional and pertains to a host in my personal home network.
Now lets add some Ruby support:
[username@hostname ~]$ gem install ruby-oci8
Fetching: ruby-oci8-2.1.7.gem (100%)
Building native extensions. This could take a while...
Successfully installed ruby-oci8-2.1.7
Parsing documentation for ruby-oci8-2.1.7
Installing ri documentation for ruby-oci8-2.1.7
Done installing documentation for ruby-oci8 after 2 seconds
1 gem installed
[username@hostname ~]$ irb
2.1.2 :001 > require 'oci8'
Warning: NLS_LANG is not set. fallback to US7ASCII.
=> true
2.1.2 :002 > o = OCI8.new('railstest','ra1lst3st','192.168.1.14/xe')
=> #<OCI8:RAILSTEST>
2.1.2 :003 > o.exec('select * from issues') do |r| puts r.join(','); end
10000,Generic Issue,#<OCI8::CLOB:0x9f9d34c>,1,,OTHER,Linux,,jh3494,2014-08-19 00:11:19 -0500,2014-08-19 00:11:19 -0500
10001,Port Flapping,#<OCI8::CLOB:0x9f9be98>,2,,CISCO,Cisco-IOS,,jh3494,2014-08-19 00:11:19 -0500,2014-08-19 00:11:19 -0500
{--SNIP--}
10023,test,#<OCI8::CLOB:0x9f7b800>,1,,CSS,Linux,,ab1234,2014-08-19 00:20:46 -0500,2014-08-19 00:20:46 -0500
=> 24
2.1.2 :004 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment