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?

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-04-07

29日目 Railsのインストール
https://qiita.com/robamimim/items/cf3f5b783f3391d88b0c

続きです。

Ruby on Railsをインストールしたので、次はGitでソースをもってきて起動です!

こちらの記事を参考にしました。

30分でできるRuby on RailsとGitHubやエディタまわりの環境構築
https://qiita.com/_kanacan_/items/59f3959169c41a167b1e

GitHubからソースをもってくる。

GitHub上のcloneボタンからURLをコピーして
git clone でソースをとってきます。

16:00:23 ~/Documents/GitHub/HtttSon $ git clone https://github.com/hogehoge/hattatsuson-app.git
Cloning into 'hattatsuson-app'...
remote: Enumerating objects: 147, done.
remote: Counting objects: 100% (147/147), done.
remote: Compressing objects: 100% (114/114), done.
remote: Total 147 (delta 19), reused 147 (delta 19), pack-reused 0
Receiving objects: 100% (147/147), 37.10 KiB | 4.64 MiB/s, done.
Resolving deltas: 100% (19/19), done.
16:00:33 ~/Documents/GitHub/HtttSon $ ls
hattatsuson-app
$ ls hattatsuson-app/
Gemfile		app		db		public		vendor
Gemfile.lock	bin		lib		storage
README.md	config		log		test
Rakefile	config.ru	package.json	tmp

よさそう。

Railsを起動する。

ところで、これどうやって起動するんだろう???

初心者向けRuby on Rails入門【開発環境から学習方法まで】
http://proengineer.internous.co.jp/content/columnfeature/11805

ここを参考に。rails s ですね。

 $ rails s
Usage:
  rails new APP_PATH [options]

(中略)

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.

・・・起動しない。
http://localhost:3000/ とうぜん応答なし。

ううむ。

Railsコケる。場所をしらべる

何がコケているんだろう?

 $ rails server
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)

 $ rails -v
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)

 $ rbenv -v
rbenv 1.1.1

 $ ruby -v
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)

rails server rails -v そして ruby -vもだめ?

もういちど source

$ source ~/.bash_profile
-bash: eval: line 35: syntax error: unexpected end of file
[~]
 $ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
[~]

んんん??? 35行もないのに???
しかしruby -vは通る。

git cloneしたパスへ移動してrails s

$ cd Documents/GitHub/HtttSon/hattatsuson-app/
$ ls
Gemfile		Rakefile	config		lib		public		tmp
Gemfile.lock	app		config.ru	log		storage		vendor
README.md	bin		db		package.json	test

$ rails s
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)

なんで? ruby -v はどうでしょう。

$ ruby -v
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)

ruby -v もうごかない!

 $ cd 
 $ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]

ところが、ホームディレクトリならruby -vがうごく。
.bash_profileを戻して。
どこでコケるか調べてみる。

ホームディレクトリはOK。

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

git cloneしたディレクトリも大丈夫。

$ cd Documents/GitHub/HtttSon/hattatsuson-app/
$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

rails s実行

[16:40:30 5 hattatsuson-app]$ 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.

railsコマンドがない。バージョンが古いのは、、、そうでした。

$ which ruby
/usr/bin/ruby
$ which bundle
/usr/local/bin/bundle

rubyとbundleのパス、古い方をみています。

.bash_profileにがっちり書いてみる。くどいかな。

$ 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.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
$ bundle -v
Bundler version 2.0.1

ここまでOK、さてgit cloneの場所へ。

$ cd Documents/GitHub/HtttSon/hattatsuson-app/
$ ruby -v
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)
$ 

なんでやねーん!!!
どうやら場所が悪いみたい。.bash_profileは無罪なので戻しておきます。

Rubyが動かない場所を調べてみる。

$ cd 
$ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
# ホームはOK

$ cd Documents/
$ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
# ここもOK

$ cd GitHub/
$ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
# OKOK

$ cd HtttSon/
$ ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
# 大丈夫だなあ

$ cd hattatsuson-app/
$ ruby -v
rbenv: version `2.5.0' is not installed (set by /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/.ruby-version)
# おっ・・・Git Cloneしたディレクトリで!`.ruby-version`って???

$ cat .ruby-version
2.5.0[20:30:07 51 hattatsuson-app]$ 
$ 
# おまえかー!

Git CloneしたRubyのバージョンが2.5.0!

rbenv install 2.5.0 でローカルのバージョンと揃えてみよう。

$ rbenv install 2.5.0
ruby-build: use openssl from homebrew
Downloading ruby-2.5.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.bz2
Installing ruby-2.5.0...
ruby-build: use readline from homebrew
Installed ruby-2.5.0 to /Users/robamimim/.rbenv/versions/2.5.0

$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin18]

よし!

$ rails s
rbenv: rails: command not found

The `rails' command exists in these Ruby versions:
  2.4.5

rails2.4.5 にしかない。
ということは・・・2.5.0になったので、

2.5.0gem install rails してみる。

$ gem install rails
Fetching: concurrent-ruby-1.1.5.gem (100%)
Successfully installed concurrent-ruby-1.1.5
Fetching: i18n-1.6.0.gem (100%)

(中略)

sprockets-rails, rails after 66 seconds
39 gems installed
$ 

なんかどっさり入った。rails s いけるかな。

$ rails s
Traceback (most recent call last):
	4: from bin/rails:3:in `<main>'
	3: from bin/rails:3:in `load'
	2: from /Users/robamimim/Documents/GitHub/HtttSon/hattatsuson-app/bin/spring:8:in `<top (required)>'
	1: from /Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler (LoadError)
[20:57:38 57 hattatsuson-app]$ 

bundlerってなんだっけ。
エラーのもとを見てみる。

$ head -n 70 /Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb | cat -n

(中略)

    54	    # If there are no unresolved deps, then we can use just try
    55	    # normal require handle loading a gem from the rescue below.
    56	
    57	    if Gem::Specification.unresolved_deps.empty? then
    58	      RUBYGEMS_ACTIVATION_MONITOR.exit
    59	      return gem_original_require(path)
    60	    end

またバージョン違い?
bundlerのバージョンを見てみると・・・

$ bundler -v
Traceback (most recent call last):
	2: from /Users/robamimim/.rbenv/versions/2.5.0/bin/bundler:23:in `<main>'
	1: from /Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)
$ cd
[21:56:00 18 ~]$ bundler -v
Bundler version 2.0.1
[21:56:09 19 ~]$ 

こっちも同じエラー。
can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException) で検索したら同じエラーにひっかかってる人が・・・って、これ前に見た事ある。同じエラーにまたひっかかってるー:sob:

can't find gem bundler (>= 0.a) with executable bundle 対応
https://qiita.com/sshuuu/items/213b4e82167317e1ebb3

Gemfile.lockと環境が違う時のエラーらしい。ということは。

cat Gemfile.lock
(中略)
RUBY VERSION
   ruby 2.5.0p0

BUNDLED WITH
   1.16.4
```

これだ!
### bundlerを`1.16.4`にしてみよう。

```
$ gem install bundler -v 1.16.4
Fetching: bundler-1.16.4.gem (100%)
Successfully installed bundler-1.16.4
Parsing documentation for bundler-1.16.4
Installing ri documentation for bundler-1.16.4
Done installing documentation for bundler after 5 seconds
1 gem installed
$ bundle -v
Bundler version 1.16.4
```

よし!

```
$ rails s
Could not find rake-12.3.2 in any of the sources
Run `bundle install` to install missing gems.
``` 
うーん、だめか。

### `rake-12.3.2`が足りないので
### `bundle install`してみる。

```
$ bundle install
Fetching gem metadata from https://rubygems.org/............
Fetching rake 12.3.2
Installing rake 12.3.2
Using concurrent-ruby 1.1.5

(中略)

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/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

extconf failed, exit code 1

Gem files will remain installed in
/Users/robamimim/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/pg-1.1.4
for inspection.
Results logged to
/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/gem_make.out

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
$ 
```

rakeだけじゃなく、すんごいたくさんインストールされました。大丈夫なのかなこれ。
最後こけて終わったけど・・・`rails s`したらどうなるかな。

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

`pg-1.1.4`これは要るものらしい。

30分でできるって聞いたのにー!
(続く)
[30日目 Ruby on Rails を起動したい その2](https://qiita.com/robamimim/items/073e13c23611d66d626d)




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?