macOS High Sierra(10.13.4)にRailsを導入
このページを参考にしてたら、最後の方でrailsアプリを作る時に以下のようなメッセージが出た。
% bundle exec rails new blog ・ ・ run bundle install Traceback (most recent call last): /usr/local/opt/ruby/bin/ruby: No such file or directory -- /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/exe/bundle (LoadError) run bundle exec spring binstub --all Traceback (most recent call last): /usr/local/opt/ruby/bin/ruby: No such file or directory -- /usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/exe/bundle (LoadError)
過去にインストールしたgemを見に行った(ls /usr/local/lib/ruby/gems/2.5.0/gems/
を実行した)ら、bundlerが無かった。
Macにデフォルトで入っているbundlerは、以下の通り。
% which bundle /usr/local/bin/bundle % bundle -v Bundler version 1.16.1
なので、bundlerのgemファイルをバージョン1.16.1で指定してインストール。
% gem install bundler -v "1.16.1" Fetching: bundler-1.16.1.gem (100%) bundler's executable "bundle" conflicts with /usr/local/bin/bundle Overwrite the executable? [yN] N ERROR: Error installing bundler: "bundle" from bundler conflicts with /usr/local/bin/bundle
↑Overwrite the executable? [yN]「実行ファイルを上書きしますか?」の所は、N「しません」で指定。
これで/usr/local/lib/ruby/gems/2.5.0/gems/bundler-1.16.1/exe/bundle
が入ったので上手くいきました。
後でbundlerに不都合が起きなければ良いけど…。
本当はrailsコマンドが取ってきているbundlerのリンク
/usr/local/lib/ruby/gems/2.5.0/gems/bundler-*/exe/bundle
を
Mac仕様/usr/local/bin/bundle
に変えたいよね。
僕はやり方が分からないので、誰か教えて下さい^_^;
rbenv:rubyのバージョン管理を行ってくれるツール
% rbenv versions
インストール済みのrubyのバージョンの一覧表示。
% rbenv global 使いたいバージョン
使用するrubyのバージョンを指定。
% rbenv local 使いたいバージョン
実行したディレクトリ以下のrubyのバージョンを指定。
% rbenv local --unset
rbenv localを解除。
Bundler:複数のgem(rubyのライブラリ)間の互換性を管理してくれるツール。Gemfileにインストールしたいgemを記述し、bundleでインストール。
% gem update bundler
Bundlerのアップデート。
% bundle init
実行したディレクトリ内にGemfileを生成。
% bundle install --path=vendor/bundle
BundlerでGemfileに書かれたgemをインストール&管理。
% bundle exec “gemコマンド”
Bundlerでインストールしたgemを実行。
bundle install --without “環境名”
Gemfileに書かれている “環境名” 以外のgemをインストール。
- Gemfileの記述方法
gem 'gem名', '>= バージョン'
"バージョン" より上だったら、gemの最新バージョンをインストール。
gem 'gem名', '~> バージョン'
gemの "バージョン" の中で最新のマイナーバージョン1をインストール。
group :”環境名” do “この環境にインストールしたいgemを列挙” end
環境(development[開発環境]、test[テスト環境]、production[本番環境]など)別にインストールしたいgemを分ける。
-
“4.0.0” だったら、"4.0.*“ の中で、一番 ”*“ の数字が大きいバージョン。"4.1.*” から上はインストールしない。 ↩