Ruby on Rails + postgresql の環境構築

Ruby on Rails 3 + postgresql 8.1.1の環境構築

1. postgresqlと連携するために必要なpgをインストール

■ pgをインストール

# gem install pg
→失敗。pg_configがないと怒られた。

■ pg_configが必要なので「postgresql-devel」をインストール

# yum install postgresql-devel
# which pg_config
/usr/bin/pg_config

成功。

■ 再びpgをインストール

# gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
# gem list | grep pg
pg (0.11.0)

成功。

2. サンプルアプリケーション作成

# rails new hello -d postgresql
(省略)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

成功。しかしメッセージが気になる。

3. サーバの起動

# cd hello/
# rails server
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
(省略)

失敗。

■以下を参考にGemfileを修正してbundle installを実行
http://d.hatena.ne.jp/kurusaki/20111106/1320584941

# vi Gemfile
→末行に以下を追加
---
gem 'execjs'
gem 'therubyracer'
---
# bundle install
(省略)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

       /usr/local/bin/ruby extconf.rb
creating Makefile

make
compiling v8_try_catch.cpp
make: g++: コマンドが見つかりませんでした
make: *** [v8_try_catch.o] エラー 127

Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/therubyracer-0.9.9/ext/v8/gem_make.out
An error occured while installing therubyracer (0.9.9), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.9.9'` succeeds before bundling.

■ g++をインストール

# yum install gcc-c++

■再びサーバ起動を実行

# rails server

起動した。
http://localhost:3000/ でアクセス成功


2011-11-23



最終更新:2011年11月23日 23:57
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。