Bash on WindowsでRVMインストールからRuby on Rails環境構築まで
※検証環境はWindows 10 Pro Insider PreviewのOSビルド14352.1002です。
Bash on Windows(正確にはBash on Ubuntu on Windowsですね)の環境を作って壊してまた作る日々です。
ようやくrvmのインストールからRuby on Rails環境構築までが上手いこといくようになったので、備忘録的に書き起こしておきます。
まぁ正直、最初のバージョンからちゃんと動いてるっぽい*1ことも考慮するとrbenv使った方がいいんじゃないかな(以下Qiitaの記事参照)
rvmのインストール
まずはgitをインストール。
sudo apt-get install
curlはインストールされているようなので、そのままrvmのインストール。公開鍵の設定をしてからインストール実行。
curl -sSL https://rvm.io/mpapis.asc | gpg --import - curl -L https://get.rvm.io | bash -s stable
~/.bashrcの末行に以下を追加。
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
.bashrcを再読み込み。
source ~/.bashrc
一応rvmのバージョン確認を実行して正常にインストールされていることを確認。
rvm -v rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
Rubyのインストール
rvm経由でRubyのインストール。とりあえずバージョンは2.3.0を選択。
rvm install ruby-2.3.0
インストールが完了したら一応バージョン確認。
ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
Ruby on Railsのインストール
まずはnodejsのインストール。
sudo apt-get install nodejs
一応Rails環境用のgemsetを作っておく。globalが散らかってもいいという方はご自由に。
rvm gemset create rails rvm gemset use rails
環境作成用のディレクトリを作成して移動。
mkdir /mnt/c/BashOnWindows/src/rails/ cd /mnt/c/BashOnWindows/src/rails/
Railsのインストール。割とすんなりいけるはず。
gem install rails
おもむろにrails newする。プロジェクト名は任意で(ここではtrial01とした)
rails new trial01
作成されたディレクトリに移動してbundle installを実行。
cd trial01/ bundle install
で、エラー発生。
Unfortunately, an unexpected error occurred, and Bundler cannot continue. First, try this link to see if there are any existing issue reports for this error: https://github.com/bundler/bundler/search?q=parent+directory+is+world+writable+but+not+sticky&type=Issues If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at: https://github.com/bundler/bundler/issues/new
どうやらbashにおける新規ファイル作成時の付与権限がデフォルトのままだと「~/.bundle」ディレクトリに対する操作がうまく動かないらしい。 Bash on Windowsのissues専用GitHubで解決策を書いてくれています。ありがたい。
ということで、コメントに従って以下を実行。
umask 007 rm -rf ~/.bundle bundle install
正常に実行完了!お待ちかねのrails sを実行。
rails s
ブラウザを開いて「http://localhost:3000」にアクセス。無事に動いてます。
ちなみに/mnt/c/配下の領域に環境作成用ディレクトリを作成しているので、Windows側のVSCode等で編集できます。
これでRailsアプリケーションの開発環境が構築できました。本番環境へのデプロイ等々が心配な感じですが、そのあたりは順番に実験していきます。
疲れた。