温馨提示×

centos能否用yum装postgresql

小樊
41
2026-09-12 07:53:26
栏目: 云计算

可以的,CentOS 可以使用 yum 安装 PostgreSQL,但需要注意几点:

1. 系统自带仓库(直接用 yum)

CentOS 默认仓库里就带有 PostgreSQL,但版本通常比较旧

yum list postgresql*
yum install -y postgresql-server postgresql

安装后初始化(CentOS 7 示例):

postgresql-setup initdb
systemctl start postgresql
systemctl enable postgresql

⚠️ CentOS 7 自带一般是 PostgreSQL 9.2,CentOS 8 以后默认用 dnf,但也可用 yum(兼容)


2. 使用 PostgreSQL 官方 YUM 仓库(推荐)

如果你想要新版本(12 / 13 / 14 / 15 / 16),建议用官方源:

# 以 PostgreSQL 15 为例(CentOS 7)
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql15-server postgresql15

初始化并启动:

/usr/pgsql-15/bin/postgresql-15-setup initdb
systemctl start postgresql-15
systemctl enable postgresql-15

3. 小总结

  • ✅ 能用 yum
  • ✅ 官方源更推荐(版本新、更新快)
  • ❌ 默认源版本偏旧

如果你是 CentOS 几 + 想要哪个 PostgreSQL 版本,我可以给你精确命令。

0