LoginSignup
13
14

More than 5 years have passed since last update.

Windows Subsystem for Linux(WSL)でRails開発できるのでは?と思って環境構築してみました。

今はVagrantで開発してるので、これが使えそうなら面倒くささが少し軽減するかなーと思ってます。
なお、この記事ではDBはSQLiteのつもりということで、MySQLは入れてません。

WSLの環境準備など

WSLのインストールはこのあたりを参考に。
http://qiita.com/Aruneko/items/c79810b0b015bebf30bb

Gitはインストールしておきます。

sudo apt install git

Railsで要求されるのでNode.jsもインストールします。

sudo apt install nodejs

umask設定しておかないとRailsが警告を出すので設定しておきます。

echo 'umask 022' >> ~/.bash_profile
source ~/.bash_profile

RubyとRailsのインストール

rbenvをインストールします。
aptでインストールするとRubyのバージョンが古いのでGitHubから。

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

Rubyは何も考えず2.3.0をインストール。

rbenv install 2.3.0
rbenv global 2.3.0

Railsをインストール。

gem install bundler
gem install rails
rbenv rehash

Railsプロジェクト作成

前提として、RailsのプロジェクトをWindows上のC:\Users\hoge\RailsProjects以下に置くことにします。
WSLから扱いやすいようにシンボリックリンクを作っておきます。

ln -s /mnt/c/Users/hoge/RailsProjects projects

cd projects

Railsプロジェクトを作成します。

rails new example

cd example

bundle install

WSLのファイルシステムはEventedFileUpdateChecker対応してないようなので修正します。

config/environments/development.rb
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
↓
config.file_watcher = ActiveSupport::FileUpdateChecker

起動します。

rails s

起動できた!

startedrails.png

いったんここまで。

引っかかったポイントまとめ

umask

WSLインストールしてデフォルトの状態だとumask 002っぽい。
そのまま進めていったRailsから警告が出ました。

/home/hoge/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/app_loader.rb:40: warning: Insecure world writable dir /home/hoge/.rbenv/versions in PATH, mode 040777

これは後でchmod -R go-w ~/.rbenvしても大丈夫です。

JavaScriptランタイム

何も考えずに進めたらjsのランタイムが無いよって怒られました。

/home/hoge/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.13.5/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

Node.jsをインストールして解決。

EventedFileUpdateChecker

file_watcherがEventedFileUpdateCheckerのまま起動したら怒られました。

/home/hoge/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rb-inotify-0.9.7/lib/rb-inotify/watcher.rb:74:in `initialize': Invalid argument - Failed to watch "/home/hoge/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/locale": the given event mask contains no legal events; or fd is not an inotify file descriptor. (Errno::EINVAL)

Bash on WindowsはFilesystem watchに対応していないためらしい。

同じようにWSLでRailsしてる記事がありましたので、参考にさせていただきました。
http://qiita.com/nisshiee/items/9a3b01ac558dabf408ae

13
14
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
13
14