工作需要在ubuntu上安装Oracle InstantClient,按道理也比较简单,今天就将安装过程记录下来。
环境:
Ubuntu14.04 LTS Server
因为服务器用的是 Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
所以按照对应版本下载 InstantClient:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
根据要求,我分别下载了Basic、SDK和Sqlplus包。
下面介绍两种安装方式:
一、直接下载相关ZIP包,这种方式最为简单
1、将三个ZIP包解压之后,合并到一起,然后上传到Ubuntu的某个用户下
2、默认文件夹为instantclient_12_1,设置775权限即可
$ sudo chmod 775 -R instantclient_12_1/
3、测试程序运行,显示内部服务器错误。报错信息如下:
Oracle Client library cannot be loaded: libclntsh.so
提示无效的命令,这肯定是环境变量的问题
4、添加环境变量,然后执行没有问题
$ export PATH=/home/lst001/pack/instantclient_12_1/:$PATH
$ export LD_LIBRARY_PATH=/home/lst001/pack/instantclient_12_1/:$LD_LIBRARY_PATH
5、我们同样可以将该环境变量添加到系统级别,这时候每次重启就直接读取环境变量了
$ sudo vi /etc/profile
将上面的信息添加到该文件的后面
然后生效环境变量
$ source /etc/profile
$ echo $PATH
/home/lst001/pack/instantclient_12_1/:/home/lst001/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
这样就安装完毕了。
二、下载相关的RPM包
这种方式就比较麻烦了,因为RPM包是红帽和CentOS才识别的,如何才能在Ubuntu上安装RPM呢?
1、安装alien工具
apt-get install alien
2、使用alien命令将RPM转换为Ubuntu识别的deb包
$ sudo alien -k oracle-instantclient-basic-10.2.0.5-1.x86_64.rpm
oracle-instantclient-basic_10.2.0.5-1_amd64.deb generated
$ sudo alien -k oracle-instantclient-devel-10.2.0.5-1.x86_64.rpm
oracle-instantclient-devel_10.2.0.5-1_amd64.deb generated
$ sudo alien -k oracle-instantclient-sqlplus-10.2.0.5-1.x86_64.rpm
oracle-instantclient-sqlplus_10.2.0.5-1_amd64.deb generated
3、使用dpkg命令安装deb包
$ sudo dpkg -i oracle-instantclient-basic_10.2.0.5-1_amd64.deb
Selecting previously unselected package oracle-instantclient-basic.
(Reading database … 61710 files and directories currently installed.)
Preparing to unpack oracle-instantclient-basic_10.2.0.5-1_amd64.deb …
Unpacking oracle-instantclient-basic (10.2.0.5-1) …
Setting up oracle-instantclient-basic (10.2.0.5-1) …
Processing triggers for libc-bin (2.19-0ubuntu6.5) …
$ sudo dpkg -i oracle-instantclient-devel_10.2.0.5-1_amd64.deb
Selecting previously unselected package oracle-instantclient-devel.
(Reading database … 61725 files and directories currently installed.)
Preparing to unpack oracle-instantclient-devel_10.2.0.5-1_amd64.deb …
Unpacking oracle-instantclient-devel (10.2.0.5-1) …
Setting up oracle-instantclient-devel (10.2.0.5-1) …
$ sudo dpkg -i oracle-instantclient-sqlplus_10.2.0.5-1_amd64.deb
Selecting previously unselected package oracle-instantclient-sqlplus.
(Reading database … 61768 files and directories currently installed.)
Preparing to unpack oracle-instantclient-sqlplus_10.2.0.5-1_amd64.deb …
Unpacking oracle-instantclient-sqlplus (10.2.0.5-1) …
Setting up oracle-instantclient-sqlplus (10.2.0.5-1) …
4、系统会默认安装在如下路径
supermap@computer:/usr/lib/oracle/10.2.0.5/client64$ pwd
/usr/lib/oracle/10.2.0.5/client64
5、同样,我们将环境变量添加上去即可
export ORACLE_HOME=/usr/lib/oracle/10.2.0.5/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
相对来说,还是第一种方法比较简单,但是通过第二种方法也学习到了如何在必须安装RPM条件下的解决办法!