1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Gem][Rails][Postgresql] gem pg がinstallできない (Your version of PostgreSQL (9.2.22) is too old) 解決法

Last updated at Posted at 2024-03-30

概要

Centos 7に Rails にgem 'pg' を入れたい。
そのままyum install postgresql-server だとversion 9.2 が入るが、(以下)
最近の gem 'pg' を使うには >9.3 である必要があるため、エラー

$ bundle install
...
Your PostgreSQL is too old. Either install an older version of this gem or upgrade your database to
at least PostgreSQL-9.2.
Error..

補足

CentOS 7 にpostgresql-15 installの流れは以下。

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql15-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15

もし古い postgresql が残っていたら削除

$ yum list installed | grep postgre
postgresql.x86_64                15.6-1PGDG.rhel7              @pgdg
postgresql-devel.x86_64          15.6-1PGDG.rhel7              @pgdg
postgresql-libs.x86_64           15.6-1PGDG.rhel7              @pgdg
postgresql-server.x86_64         15.6-1PGDG.rhel7              @pgdg

$ sudo yum remove postgresql postgresql-libs -y

補足

再度、CentOS 7 に入れようと思ったら、
gem pg に必須の postgresql-devel.x86_64 が上手く入らなかった..
->
以下 URLで postgresql-devel を検索して
↑で入れた version 15.6-1PGDG.rhel7
例えば、postgresql15-contrib-15.6-1PGDG.rhel7.x86_64.rpm
のURL をコピーし yum insatll..
https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-7-x86_64/

sudo yum install https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-7-x86_64/postgresql15-devel-15.7-1PGDG.rhel7.x86_64.rpm

解決法

(↑で) 最新の version 15を入れた後、
以下で confiを指定して、実行すれば bundle install が通る

bash
$ bundle config build.pg --with-pg-config=/usr/pgsql-15/bin/pg_config # 15 が入っている前提
$ bundle
...
OK
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?