LoginSignup
0
0

More than 5 years have passed since last update.

Windows Subsystem for LinuxのUbuntu 16.04にRailsをインストールする

Last updated at Posted at 2018-03-06

はじめに

Windows Subsystem for LinuxのUbuntu 16.04にRuby on Rails (5.1.5)をインストールした際に何点かハマりました。最終的に上手くいった手順を備忘録としてメモしておきます。

誤りや修正点等ございましたらコメントしていただけると嬉しいです:bow:

実行環境

  • Windows 10 Home (Fall Creators Update適用済)
    • Windows Subsystem for LinuxでUbuntu 16.04.4 LTSを起動
  • 新規UNIXユーザー作成直後からスタート

Rubyのインストール

Rubyをビルドする際に必要なパッケージをインストールします。

console
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install -y git build-essential libssl-dev libreadline-dev

rbenv、ruby-buildをインストールします。

初めはここでsudo apt install rbenv ruby-build...としてaptでインストールしたのですが、どうやらインストールされるrbenv、ruby-buildのバージョンが古い?ようで、インストールできるRubyのバージョンの選択肢が少ないという事象に陥りました。

以下の通り公式のレポジトリから直接持ってくると上手くいきました。

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

~/.profileを編集し以下の行を追加します。

~/.profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

~/.profileをリロードします。

console
$ source ~/.profile 

記事執筆時点での最新版2.5.0をインストールします。

console
$ rbenv install 2.5.0
$ rbenv global 2.5.0

以上でRubyのインストールができました。

console
$ ruby --version
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

Railsのインストール

Railsを動かす際に必要なパッケージをインストールします。

console
$ sudo apt install -y libsqlite3-dev nodejs

(2018/11/05 追記)上記コマンドでインストールされるNode.jsのバージョンが古いため、Railsで使用するgemでエラーが出ることがありました。Node.jsをアップデートすることで解決しました。

参考「とりあえず Ubuntu で新しい Node.js, npm をインストール - Qiita


Railsをインストールします。

console
$ gem install rails
$ rbenv rehash

以上でRailsのインストールができました。
確認のためアプリを起動してみます。

console
$ rails new rails-test --skip-bundle
$ cd rails-test
$ bundle install --path vendor/bundle
$ bundle exec rails s

ブラウザでlocalhost:3000にアクセスします。
image.png
Yay!⌒°( ・ω・)°⌒:train::train::train:

参考URL

0
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
0
0