LoginSignup
19

More than 5 years have passed since last update.

CentOSにPostGISをyumでインストール(CentOS7.2, PostgreSQL9.5, PostGIS2.2)

Last updated at Posted at 2016-01-10

QGIS のためにPostgreSQL を入れたのに,PostGIS じゃないと動かない.
PostGIS を入れよう!
入らない・・・助けて!先輩!
先輩「EPELぐらい知っとけよ」
というわけで四苦八苦したのでメモ

PostGIS のインストールに必要なもの

こちらにPostGIS を入れるために必要なものは載っています.
Chapter 2. PostGIS Installation

CentOS のバージョン

$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core

PostgreSQL のバージョン

$ psql --version
psql (PostgreSQL) 9.5.0

今回は,Proj とGDAL を入れます.

各種インストール

EPEL のインストール

GDAL はEPEL が有効でないと入りません.
(PostGIS のインストール時にエラーを吐かれます)
EPEL を入れてない場合は,EPELのインストールをします.

# yum install epel-release

/etc/yum.repos.d/epel.repo にある設定ファイルを変更して,明示的に使用するように変更します.

epel.repo
# 変更前
enable=1

# 変更後
enabled=0

Proj とGDALのインストール

# yum install -y proj proj-devel proj-epsg
# yum --enablerepo=epel install gdal

PostGIS のインストール

入手できる postgis のパッケージを確認

# yum list | grep postgis
postgis.x86_64                          2.0.7-1.el7                    @epel
postgis-docs.x86_64                     2.0.7-1.el7                    epel
postgis-utils.x86_64                    2.0.7-1.el7                    epel
postgis2_95.x86_64                      2.2.4-1.rhel7                  pgdg95
postgis2_95-client.x86_64               2.2.4-1.rhel7                  pgdg95
postgis2_95-debuginfo.x86_64            2.2.4-1.rhel7                  pgdg95
postgis2_95-devel.x86_64                2.2.4-1.rhel7                  pgdg95
postgis2_95-docs.x86_64                 2.2.4-1.rhel7                  pgdg95
postgis2_95-utils.x86_64                2.2.4-1.rhel7                  pgdg95

postgis2_95 というのが PostgreSQL9.5 に合わせたものになるので、こちらをインストールします。

# yum install postgis2_95

テスト

実際にPostGIS が使えるか,テストしてみます.

$ psql -U postgres
ユーザ postgres のパスワード:
psql (9.2.14, サーバー 9.5.0)
注意: psql バージョン 9.2, サーバーバージョン 9.5.
         psql の機能の中で、動作しないものがあるかもしれません。
"help" でヘルプを表示します.

postgres=# CREATE DATABASE test;
postgres=# \connect test
psql (9.2.14, サーバー 9.5.0)
注意: psql バージョン 9.2, サーバーバージョン 9.5.
         psql の機能の中で、動作しないものがあるかもしれません。
データベース "test" にユーザ"postgres"として接続しました。
test=# CREATE EXTENSION postgis;
CREATE EXTENSION

成功です.
ついでにPostGIS のバージョンの確認

test=# SELECT PostGIS_full_version();
                                                                       postgis_full_version
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.2.1 r14555" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.2, released 2015/02/10" LIBXML="2.9.1" LIBJSON="0.11" RASTER
(1 行)

参考

Chapter 2. PostGIS Installation
PostGISをインストール[PostgreSQL9.2 – Cent6.4]
CentOS に PostGIS/GDAL/Proj をインストールする手順。
CentOS7.1 64bitのyumリポジトリにEPELを追加

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
19