LoginSignup
0
0

More than 5 years have passed since last update.

30日目 Ruby on Rails を起動したい その2

Last updated at Posted at 2019-04-08

29日目 その2 Ruby on Railsを起動したい!
https://qiita.com/robamimim/items/b087a45c6d0dd3f08c9c

続きです。

昨日のふりかえり

昨日は、Ruby on railsのアプリをローカルに展開しようとしたらエラーだらけでできず。
原因は git cloneした Gemfile.lock に書かれていたRubyのバージョンとローカルのバージョンが違うことでは?と思いました。

そこで rbenv install 2.5.0 でローカルのバージョンとそろえて
bundlerも1.16.4 でバージョンをあわせて
gem install rails でもう一度railsをインストール。

rails s すると rake-12.3.2 が足りないので bundle install して、というメッセージがでたのでその通りやってみると
pg-1.1.4 のインストールがこけたので、バンドルする前に gem install pg -v '1.1.4' --source 'https://rubygems.org/' してくださいとメッセージがでて・・・

ここまでやったのでした。

さて、今日です。

パソコンを起動して、rails s します。

$ rails s
Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

You can then rerun your "rails" command.

あらら、、、昨日の最初に戻っている?

[hattatsuson-app]$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
[hattatsuson-app]$ bundle -v
Bundler version 2.0.1
[hattatsuson-app]$ 

rubyもbundleも戻っている!?

再起動したら戻る仕様なの!?


コメントいただきました!

rbenv install しただけでは Ruby のバージョンは変わらなくて,もう一手間必要です。
まっさらの状態で使うときのデフォルトの Ruby バージョンを 2.5.0 にしたければ
rbenv global 2.5.0

さっそく。rbenv global 2.5.0

$ rbenv global 2.5.0
$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

変わらず。

何か変ですね。

$ echo $PATH
/usr/local/var/nodebrew/current/bin:/Users/robamimim/.nodebrew/current/bin:/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

パスにrubyが入っていない!

$ cat .bash_profile
# added by Anaconda3 5.3.0 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<
#eval "$(rbenv init -)"export PATH=$HOME/.nodebrew/current/bin:$PATH
export PATH=$HOME/.nodebrew/current/bin:$PATH
export NODEBREW_ROOT=/usr/local/var/nodebrew
export PATH=/usr/local/var/nodebrew/current/bin:$PATH
export PS1="[\t \# \W]\$ "

.bash_profileにrubyが入っていない!?
前日のログを見返してみると・・・

.bash_profileにrubyを追記
source ~/.bash_profile
(ホームでは).rbenvのrubyを見るようになった
git cloneの場所へ
ruby 2.5.0 is not installed → てことは.bash_profileは無罪だから戻そう!

・・・としていたのでした。
しかし、not installedの原因はgit cloneでもってきたGemfile.lockのバージョンだったということは

.bash_profileにrubyは必要だったのでは・・・???

ためしてみます。

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ which ruby
/Users/robamimim/.rbenv/shims/ruby
$ which bundle
/Users/robamimim/.rbenv/shims/bundle
$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin18]
$ 

よーし!

$ cd Documents/
$ cd GitHub/
$ cd HtttSon/
$ cd hattatsuson-app/
$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin18]
$ bundle -v
Bundler version 1.16.4

rubyとbundleはOK!

今度こそ!

$ rails s
Could not find pg-1.1.4 in any of the sources
Run `bundle install` to install missing gems.

rails s 起動しない。

ありゃ。前回 bundle install したばかりなのだけど。そう何回も打っていいものか。
念のためバックアップをとって再開です。

再度bundle install

$ bundle install
Fetching gem metadata from https://rubygems.org/............
Using rake 12.3.2   ※rakeはいりましたね!

(中略)

Fetching pg 1.1.4
Installing pg 1.1.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

(中略)

An error occurred while installing pg (1.1.4), and Bundler cannot
continue.
Make sure that `gem install pg -v '1.1.4' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  pg

pgがないからダメだって

そうそう、pg がいるって言われてたんでした。
再起動したらruby2.5.0が呼び出せなくてドタバタしてたら忘れてました。
やってみましょう。

gem install pg -v '1.1.4'

$ gem install pg -v '1.1.4'
Building native extensions. This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/pg-1.1.4/ext
/Users/robamimim/.rbenv/versions/2.5.0/bin/ruby -r ./siteconf20190409-1003-126chcy.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

(以下略)

libpq-fe.hがないからpgはダメだって。

mkmf.logを確認します。

$ sudo cat  /Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-18/2.5.0-static/pg-1.1.4/mkmf.log
find_executable: checking for pg_config... -------------------- no

--------------------

find_header: checking for libpq-fe.h... -------------------- no

"clang -o conftest -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/Users/robamimim/.rbenv/versions/2.5.0/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -pipe conftest.c  -L. -L/Users/robamimim/.rbenv/versions/2.5.0/lib -L. -L/Users/robamimim/.rbenv/versions/2.5.0/lib  -fstack-protector -L/usr/local/lib     -lruby.2.5.0-static -framework Foundation  -lpthread -lgmp -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"clang -E -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0/x86_64-darwin18 -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0/ruby/backward -I/Users/robamimim/.rbenv/versions/2.5.0/include/ruby-2.5.0 -I. -I/Users/robamimim/.rbenv/versions/2.5.0/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -pipe  conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
         ^~~~~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libpq-fe.h>
/* end */

--------------------

[20:24:02 32 hattatsuson-app]$ 

conftest.iが使いたいlibpq-fe.hがないっていう。
conftest.iがどこかっていうと、

$ sudo find / -name conftest.i
Password:
find: /.Spotlight-V100: Operation not permitted

(中略)

find: /Volumes/com.apple.TimeMachine.localsnapshots: Operation not permitted
$

ない。
もしかして conftest.c ?

$ sudo find / -name conftest.c
Password:
find: /.Spotlight-V100: Operation not permitted

(中略)

find: /Volumes/com.apple.TimeMachine.localsnapshots: Operation not permitted
$

ここにもない。うーん、どういう事なんだろう。

ひとつ戻ってlibpq-fe.hで検索するとあるわあるわ。
yumなりbrewなり、postgres.appをダウンロードするなりして、PATHに追加すればいいらしい。gemとyumの違いがわからないのですが、やってみましょう。

$ sudo yum install postgresql-devel
Password:
sudo: yum: command not found

えーっ・・・

ならばbrewで!

$ brew install postgresql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (heroku/brew, homebrew/core and homebrew/cask).

 (中略)

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
$ 

startっていい感じ!
gemはどうかな?

$ gem install pg -v '1.1.4'
Building native extensions. This could take a while...
Successfully installed pg-1.1.4
Parsing documentation for pg-1.1.4
Installing ri documentation for pg-1.1.4
Done installing documentation for pg after 1 seconds
1 gem installed
[21:15:57 43 usr]$ 

よし!
満を持しての!!!

$ rails s
Could not find puma-3.12.1 in any of the sources
Run `bundle install` to install missing gems.
$

次回、 puma-3.12.1

終わるのか、これ!?
(続く)
31日目 Ruby on Rails を起動したい その3

0
0
4

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
0
0