温馨提示×

ubuntu oracle如何装客户端

小樊
63
2026-10-04 19:55:55
栏目: 云计算

在 Ubuntu 上安装 Oracle 客户端(通常指 Oracle Instant Client 或完整 Client),常见做法如下:


一、推荐方式:Oracle Instant Client(最常用)

适合开发、连接数据库,体积小。

1. 下载 Instant Client

到 Oracle 官网下载(需登录 Oracle 账号): https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

常用包:

  • basic 或 basiclite(必须)
  • sqlplus(可选,命令行工具)
  • sdk(开发用,比如 Python cx_Oracle)

示例(以 21c 为例):

mkdir -p ~/oracle && cd ~/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/2119000/instantclient-basic-linux.x64-21.19.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/2119000/instantclient-sqlplus-linux.x64-21.19.0.0.0dbru.zip

2. 解压

unzip instantclient-basic-linux.x64-21.19.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-21.19.0.0.0dbru.zip

目录类似:

~/oracle/instantclient_21_19

3. 安装依赖

sudo apt update
sudo apt install libaio1

4. 配置环境变量

echo 'export ORACLE_HOME=~/oracle/instantclient_21_19' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export PATH=$ORACLE_HOME:$PATH' >> ~/.bashrc
source ~/.bashrc

5. 测试

sqlplus username/password@host:port/service_name

二、使用 APT(不推荐,版本旧)

Ubuntu 官方源有旧版:

sudo apt install oracle-instantclient-basic

⚠️ 版本较老,通常不推荐生产使用。


三、Python 使用 Oracle 客户端

pip install cx_Oracle

确保 LD_LIBRARY_PATH 已配置。


四、常见问题

1. 报错 libaio.so.1: cannot open shared object

sudo apt install libaio1

2. 中文乱码

设置:

export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

如果你能告诉我:

  • Ubuntu 版本(20.04 / 22.04 / 24.04)
  • 用途(开发 / 运维 / Python / Java)
  • 是否要连远程 Oracle

我可以给你更精确的命令。

0 踩