Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Last active November 12, 2024 04:26
Show Gist options
  • Save rutcreate/778ade900fa144bf9a16aa405082fb45 to your computer and use it in GitHub Desktop.
Save rutcreate/778ade900fa144bf9a16aa405082fb45 to your computer and use it in GitHub Desktop.
Install Oracle InstantClient and SQL*Plus from source on Ubuntu 20.04

Download InstantClient

mkdir -p /opt/oracle
cd /opt/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-basic-linux.x64-21.8.0.0.0dbru.zip
unzip instantclient-basic-linux.x64-21.8.0.0.0dbru.zip

Download SQLPlus

wget https://download.oracle.com/otn_software/linux/instantclient/218000/instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-21.8.0.0.0dbru.zip

After you unzip sqlplus package, you will see both lib files and sqlplus command inside directory instantclient_21_8

ls -la /opt/oracle/instantclient_21_8

Install Ubuntu dependency package

sudo apt install libaio1

Autoload LD_LIBRARY_PATH

sudo sh -c "echo /opt/oracle/instantclient_21_8 > /etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig

Add follow code to ~/.bashrc

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

Then logout and login again or run source ~/.bashrc to reload $PATH environment

Test connection

Use SQLPlus

sqlplus username:password@host:port/service_name

# password promt (better)
sqlplus username@host:port/service_name

Use Python

Install dependencies

pip install cx_Oracle

Connect to Oracle python script

import cx_Oracle as Database
user = 'username'
password = 'password'
dsn = Database.makedsn('host', 'port', service_name='service_name')
conn = Database.connect(user=user, password=password, dsn=dsn, encoding='UTF-8')

Django Database settings

Use service name

DATABASES = {
  'ENGINE': 'django.db.backends.oracle',
  'NAME': 'host:port/service_name',
  'USER': 'username',
  'PASSWORD': 'password',
}

Use SID

DATABASES = {
  'ENGINE': 'django.db.backends.oracle',
  'NAME': 'sid',
  'USER': 'username',
  'PASSWORD': 'password',
  'HOST': 'host',
  'PORT': 'port',
}

References

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst

@alessandrofuda
Copy link

alessandrofuda commented Nov 17, 2022

first line: after mkdir -p /opt/oracle add cd /opt/oracle

@rutcreate
Copy link
Author

rutcreate commented Nov 18, 2022

first line: after mkdir -p /opt/oracle add cd /opt/oracle

@alessandrofuda DONE! Thanks for point it out.

@Subodhrebel
Copy link

Subodhrebel commented Feb 5, 2024

after completion it is asking for username and password and i am using my ubuntu username and passwword showing error
ORA-12162: TNS:net service name is incorrectly specified

@rutcreate
Copy link
Author

after completion it is asking for username and password and i am using my ubuntu username and passwword showing error ORA-12162: TNS:net service name is incorrectly specified

please provide your command or code

@maranzadieg23wg
Copy link

maranzadieg23wg commented Mar 6, 2024

Good morning,
I have done all the installation to the letter, but at the time of entering username and password, I do not know which username and password to enter. If I enter the user of the computer after running

sqlplus 

I get

ORA-12162: TNS:net service name is incorrectly specified

and instead if I run

sqlplus username:password@localhost:1521/service_name

I get

ORA-12541: TNS:no listener

I would appreciate any help, thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment