How to install Oracle Instant Client on a Mac?

只谈情不闲聊 提交于 2019-12-02 18:18:44
Alex Poole

There are multiple files available for download. From the files you listed you have only downloaded and unzipped the 'basic' package.

To run the CLI (by which I assume you mean SQL*Plus) you need that package as well - the fourth in the list, titled "Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client".

The packages are arranged such that if you unzip all the ones you need from the same place they all put their files in the same directory. Unfortunately that doesn't quite work if you use Safari and have it set to open certain downloaded files; each zip file is expanded into a separate folder, with incremented names. And it deletes the zip files afterwards.

You can either disable that automatic unzipping and do it manually, or copy the files from the individual folders into a common one.

You may also need to create a symbolic link for the main client library; from inside that folder (in Terminal) you would do:

ln -s libclntsh.dylib.12.1 libclntsh.dylib

You can put that combined folder anywhere you like. You then need to add the full path to that folder to your PATH and environment variable - you can add that to your .bash_profile so you don't need to do it manually.

Once you've done that you can execute sqlplus from anywhere.

So to summarise:

  1. If you're using Safari, disable automatic opening of the zip files; from Safari->Preferences->General untick the 'Open "safe" files after downloading' checkbox.

  2. Download instantclient-basic-macos.x64-12.1.0.2.0.zip and instantclient-sqlplus-macos.x64-12.1.0.2.0.zip

  3. In Terminal go to your Downloads directory.

  4. Unzip both files:

    MacBook:Downloads alex$ unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-basic-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/BASIC_README  
      inflating: instantclient_12_1/adrci  
      inflating: instantclient_12_1/genezi  
      inflating: instantclient_12_1/libclntsh.dylib.12.1  
      inflating: instantclient_12_1/libclntshcore.dylib.12.1  
      inflating: instantclient_12_1/libnnz12.dylib  
      inflating: instantclient_12_1/libocci.dylib.12.1  
      inflating: instantclient_12_1/libociei.dylib  
      inflating: instantclient_12_1/libocijdbc12.dylib  
      inflating: instantclient_12_1/libons.dylib  
      inflating: instantclient_12_1/liboramysql12.dylib  
      inflating: instantclient_12_1/ojdbc6.jar  
      inflating: instantclient_12_1/ojdbc7.jar  
      inflating: instantclient_12_1/uidrvci  
      inflating: instantclient_12_1/xstreams.jar  
    MacBook:Downloads alex$ unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/SQLPLUS_README  
      inflating: instantclient_12_1/glogin.sql  
      inflating: instantclient_12_1/libsqlplus.dylib  
      inflating: instantclient_12_1/libsqlplusic.dylib  
      inflating: instantclient_12_1/sqlplus  
    
  5. Optionally rename and/or move the instantclient_12_1 directory to somewhere more permanent.

  6. Add the location to your path in your current session, and also in your shell profile/resource file to make it take effect on every login:

     export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    
  7. Enjoy.

    MacBook:Downloads alex$ export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    MacBook:Downloads alex$ which sqlplus
    /Users/alex/Downloads/instantclient_12_1/sqlplus
    MacBook:Downloads alex$ sqlplus
    
    SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 9 16:29:49 2016
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Enter user-name: 
    

El Capitan added system integrity protection (SIP), and one side effect of that is that exporting DYLD_LIBRARY_PATH doesn't work. That could affect running SQL*Plus from a shell script, for example. There are workarounds for the 11g instant client. The installation notes at the bottom of the download page have changed since I last did this, and it now says to hard link the library files to the user's ~/lib directory to avoid that issue. Fortunately it looks like you don't need to worry about that with the 12c client - they've fixed the way it's built.

HomeBrew saved me. I do not figure out the environment path.

1. Download the two files below from http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html.

This is necessary because of Oracle licenses.

instantclient-basic-macos.x64–11.2.0.4.0.zip and instantclient-sqlplus-macos.x64–11.2.0.4.0.zip

Put the files in ~/Library/Caches/Homebrew


PS:

in the latest versions of HomeBrew replace the above location ~/Library/Caches/HomeBrew with ~/Library/Caches/HomeBrew/downloads.

And also rename the downloaded files with the names suggested by HomeBrew.

Thanks to @manuka_m


2. Next run the following commands

$ brew tap InstantClientTap/instantclient

$ brew install instantclient-basic

$ brew install instantclient-sqlplus

Originated from Joost van Wollingen's doc

Within SQLdeveloper you will find SQLplus, that works out of the box like on Windows.

(Should start like this)

If you move the app under Application and manage to start up the SQLdeveloper-client you cant fint it here, called sql:

/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sql

To directly login, run sql and exit:

sql username/password@ADDRESS_TO_DB:1521/SID @/path/to/your/pls_file_containing_sql/test.pls

Remember to include 'exit;' at the end of your pls-file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!