在 Ubuntu 下使用 Oracle,一般有三种常见场景,我按“最常见 → 进阶”给你讲清楚,并给出可操作的步骤。
✅ 注意:Oracle 官方 不支持 Ubuntu 直接安装 Oracle Database,
所以生产环境建议用 CentOS / RHEL / Oracle Linux。
Ubuntu 主要是用来做客户端或开发环境。
适合:
去官网(需 Oracle 账号):
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
推荐下载:
basic
sqlplus
例如:
oracle-instantclient-basic-21.11.0.0.0-1.x86_64.rpm
oracle-instantclient-sqlplus-21.11.0.0.0-1.x86_64.rpm
sudo apt update
sudo apt install alien libaio1
sudo alien -i oracle-instantclient-basic-*.rpm
sudo alien -i oracle-instantclient-sqlplus-*.rpm
编辑:
nano ~/.bashrc
添加:
export ORACLE_HOME=/usr/lib/oracle/21/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
生效:
source ~/.bashrc
sqlplus user/password@//ip:1521/orcl
⚠️ 仅用于 学习 / 测试
这是 Ubuntu 下最推荐的方式
docker run -d \
--name oracle \
-p 1521:1521 \
-e ORACLE_PASSWORD=123456 \
container-registry.oracle.com/database/express:21.3.0-xe
连接:
sqlplus system/123456@//localhost:1521/XE
| 工具 | 说明 |
|---|---|
| DBeaver | 免费,支持 Oracle ✅ |
| Navicat | 商业 |
| SQL Developer | Oracle 官方 |
pip install oracledb
import oracledb
conn = oracledb.connect(
user="user",
password="pwd",
host="ip",
port=1521,
service_name="orcl"
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM dual")
print(cursor.fetchone())
libaio.so.1 缺失sudo apt install libaio1
sqlplus: command not foundecho $PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
✅ 只是用 Oracle(开发 / 连接) → Instant Client
✅ 本地学习 Oracle → Docker
❌ 生产环境 → 不要用 Ubuntu 装 Oracle Database
如果你愿意,我可以:
你现在用的是 Ubuntu 版本 + 想干什么?