LoginSignup
1

More than 3 years have passed since last update.

WSL上にRuby on railsの環境を構築する

Last updated at Posted at 2019-04-12

gitの導入

sudo apt-get install git

rbenvの導入

rbenv:Rubyのバージョンを管理するツール

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/rkh/rbenv-update.git ~/.rbenv/plugins/rbenv-update

パスを通す

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

Rubyの導入

2019/04/13時点で安定版の2.6.2を導入

rbenv install 2.6.2

うまくいかない

Inspect or clean up the working tree at /tmp/ruby-build.20190413020215.166
Results logged to /tmp/ruby-build.20190413020215.166.log

Last 10 log lines:
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20190413020215.166/ruby-2.6.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

Cコンパイラが無いせいらしい
インストール

sudo apt-get install gcc

またエラー

Inspect or clean up the working tree at /tmp/ruby-build.20190413022147.4755
Results logged to /tmp/ruby-build.20190413022147.4755.log

Last 10 log lines:
checking for _setjmp as a macro or function... yes
checking for sigsetjmp as a macro or function... no
checking for setjmp type... __builtin_setjmp
checking for prefix of external symbols... NONE
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking if make is GNU make... ./configure: line 29155: make: command not found
no
checking for safe null command for make... configure: error: no candidate for safe null command

makeコマンドがないみたい
インストール

sudo apt-get install make

またエラー

Inspect or clean up the working tree at /tmp/ruby-build.20190413022903.11877
Results logged to /tmp/ruby-build.20190413022903.11877.log

Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `apt-get install -y libssl-dev libreadline-dev zlib1g-dev` to fetch missing dependencies.

エラー文を見て必要そうなパッケージをインストール

sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev

いけた

$ rbenv install 2.6.2
Downloading ruby-2.6.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.2.tar.bz2
Installing ruby-2.6.2...
Installed ruby-2.6.2 to /home/${username}/.rbenv/versions/2.6.2

これだけだとrbenvディレクトリにのみRuby 2.6.2が適用されているので、環境全体に適用する

rbenv global 2.6.2
ruby -v
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]

railsの導入

gemは導入済み

gem -v
3.0.3

インストール

gem install rails

Node.jsの導入

rails上でサーバを起動する際にjavascriptランタイムが必要になるので、Node.jsをインストール
普通にaptコマンドでインストールするとバージョンが古かったりするので、一工夫必要

まずは普通にnodejsとnpmをインストール

sudo apt install -y nodejs npm

次にn packecge(Node.jsのバージョン管理パッケージ)をインストール

sudo npm install n -g

再度Node.jsをインストール

sudo n stable

先に入れたNode.jsをアンイストール

sudo apt purge -y nodejs npm

以下実行

exec $SHELL -l

最新安定版がインストールされていることを確認

$ node -v
v10.15.3

以上

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
1