setup Rails 5 on Bash on Ubuntu on Windows
BashOnUbuntuOnWindowsでRails5をセットアップする
Install Bash
まずはWindows10(OS build 14393.10 以降)を用意する。
ControlPanelのプログラムメニュー内にある Windowsの機能の有効か無効か を選択する。その中にある Windows Subsystem for Linux にちぇっくを入れて再起動をかける。 これでBashのインストールができるはず。。
bash settings
bash を起動してテキトーにユーザ設定とかする。
apt-getのアップデートとか行う
$ apt-get update $ apt-get upgrade
gitをインストールする
$ apt-get install git
install ruby
rbenvをインストールする。
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv $ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build $ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash # rbenvがインストールできたかどうかバージョン確認する $ rbenv -v rbenv 1.0.0-30-hoge
~/.bashrcに以下を追記します。
export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"
Rubyのインストールに必要なもろもろのものをインストールする。
$ apt-get install gcc build-essential libssl-dev libreadline-dev zlib1g-dev
ようやくrubyをインストールする。今回はRuby2.3.1をインストールする。
$ rbenv install 2.3.1
かなり時間がかかるのでゲームでもしながら気長に待つ。
使用するRubyのバージョンを設定し、確認する
$ rbenv global 2.3.1 $ ruby -v
install Rails
gemをアップデートしておく
$ gem update --system
bundlerをインストールする。
$ gem install bundler
ここでNokogiri対策をしておく。
$ apt-get install libxml2 libxml2-dev libxslt-dev $ bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/include/libxml2"
いよいよrailsをインストールする!
$ gem install rails
ここもそこそこ時間がかかるので、気長に待つ。
とくになにも設定しなければsqliteを使うことになるのでsqliteをインストールする。Postgresは後日対応。。。
$ apt-get install sqlite3
ここでRailsプロジェクトを作ってみる
$ rails new test_project --skip-bundle $ cd test_project $ bundle install --path vender/bundle/
Railsサーバを立ち上げてみる。。。
$ bundle exec rails server
bundle がうまくいかない
$ bundle --- ERROR REPORT TEMPLATE ------------------------------------------------------- ... Error details ArgumentError: parent directory is world writable but not sticky ...... $
的なエラー。bundleのキャッシュファイルがなにかしら邪魔しているようなので、そのファイルの書き込み権限を変更する。
$ chmod -R +t ~/.bundle/cache
StackOverFlow
Rails server が動かない
$ bundle exec rails s /usr/local/lib/ruby/gems/2.3.1/gems/bundler-1.12.5/lib/bundler/runtime.rb:80:in 'rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)`
therubyracerを有効にすればいいらしい
# Gemfile gem 'therubyracer', platform: :ruby
Qiita
まだうごかない
$ bundle exec rails s => Booting Puma => Rails 5.0.0.rc1 application starting in development on http://localhost:3000 => Run 'rails server -h` for more startup options Exiting /home/josh/.rvm/gems/ruby-2.3.1@frontend/gems/rb-inotify-0.9.7/lib/rb-inotify/watcher.rb:74:in `initialize': Invalid argument - Failed to watch "/home/josh/.rvm/gems/ruby-2.3.1@frontend/gems/activesupport-5.0.0.rc1/lib/active_support/locale": the given event mask contains no legal events; or fd is not an inotify file descriptor. (Errno::EINVAL)
config/environments/development.rbの編集する。
# Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.file_watcher をコメントアウトする。
github
これでぼくは動きました!!
References
windowsのbashでRails環境を構築してみる。(Windows 10 Insider Preview 14316)















