スポンサーリンク
Ruby と Ruby on Rails のインストールメモ(Ubuntu向け)を書いておきます。極力公式情報に従い、Ruby on Rails のインストール手順終了までを扱います。ただし、公式文書に従ってエラーが出た箇所については、独自に対策しています。
スポンサーリンク
Rubyのインストール
Rubyをイントールします(https://www.ruby-lang.org/en/documentation/installation/#apt)。
$ sudo apt-get install ruby-full
gem も入ります。
$ gem --version 1.8.23
ただ、「ruby 1.9.3p484」という古いものが入ってしまったのですが、Ruby on Rails的には「We recommend Ruby 2.2 or newer for use with Rails.」のようなので、更新します。
Git
まず、gitを準備します。
$ sudo apt-get install git
rbenv
rbenv を ~/.rbenv に checkout してきます。
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
~/.rbenv/bin を $PATH に追加し、rbenv init を登録します。
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc<br /> echo 'eval "$(rbenv init -)"' >> ~/.bashrc
(~/.bashrc の部分は、適宜変更。zshの場合は ~/.zshrc に。)
シェルを再起動(「$ source ~/.bashrc」でもいいはず)して、「$ type rbenv」を実行して、「rbenv は関数です」と表示されればインストール成功です(「bash: type: rbenv: 見つかりません」と表示されたら失敗しているか、再起動忘れ)。
ruby-build
rbenvプラグインのruby-buildを入れます。
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
このコマンド一つでインストール完了です。
最新版のRubyをインストール
これで、特定のバージョンのRubyをインストールできます。
まず、インストール可能なバージョンを特定します。
$ rbenv install -l
Available versions: 1.8.6-p383 1.8.6-p420 1.8.7-p249 1.8.7-p302 1.8.7-p334 1.8.7-p352 1.8.7-p357 1.8.7-p358 1.8.7-p370 1.8.7-p371 1.8.7-p374 1.8.7-p375 1.9.1-p378 1.9.1-p430 1.9.2-p0 1.9.2-p180 1.9.2-p290 1.9.2-p318 1.9.2-p320 1.9.2-p326 1.9.2-p330 1.9.3-dev 1.9.3-preview1 1.9.3-rc1 1.9.3-p0 1.9.3-p125 1.9.3-p194 1.9.3-p286 1.9.3-p327 1.9.3-p362 1.9.3-p374 1.9.3-p385 1.9.3-p392 1.9.3-p429 1.9.3-p448 1.9.3-p484 1.9.3-p545 1.9.3-p547 1.9.3-p550 1.9.3-p551 2.0.0-dev 2.0.0-preview1 2.0.0-preview2 2.0.0-rc1 2.0.0-rc2 2.0.0-p0 2.0.0-p195 2.0.0-p247 2.0.0-p353 2.0.0-p451 2.0.0-p481 2.0.0-p576 2.0.0-p594 2.0.0-p598 2.0.0-p643 2.0.0-p645 2.1.0-dev 2.1.0-preview1 2.1.0-preview2 2.1.0-rc1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0-dev 2.2.0-preview1 2.2.0-preview2 2.2.0-rc1 2.2.0 2.2.1 2.2.2 2.3.0-dev jruby-1.5.6 (以降略)
Ruby on Rails では、
We recommend Ruby 2.2 or newer for use with Rails. Rails requires Ruby 1.9.3 or newer. (引用元)
となっているので、1.9.3以降が必須で、2.2以上が推奨されています。
すると、現状では、2.2.0、2.2.1、2.2.2の3択となると思うのですが、ここでは最新の 2.2.2 にしておきます。
$ rbenv install 2.2.2 Downloading ruby-2.2.2.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/5ffc0f317e429e6b29d4a98ac521c3ce65481bfd22a8cf845fa02a7b113d9b44 Installing ruby-2.2.2... BUILD FAILED (Ubuntu 14.04 using ruby-build 20150719-7-ge40e84f) Inspect or clean up the working tree at /tmp/ruby-build.20150722233833.10887 Results logged to /tmp/ruby-build.20150722233833.10887.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. Configure options used: --prefix=/home/did2/.rbenv/versions/2.2.2 LDFLAGS=-L/home/did2/.rbenv/versions/2.2.2/lib CPPFLAGS=-I/home/did2/.rbenv/versions/2.2.2/include
よく見ると、エラーが出ています。そこで、指示通り、次を実行しました(環境、実行結果によってコマンドが変わります)。
$ sudo apt-get install -y libssl-dev libreadline-dev zlib1g-dev
これを終えた上で、もう一度インストールコマンドを実行した結果がこちらです。
$ rbenv install 2.2.2 Downloading ruby-2.2.2.tar.gz... -> https://dqw8nmjcqpjn7.cloudfront.net/5ffc0f317e429e6b29d4a98ac521c3ce65481bfd22a8cf845fa02a7b113d9b44 Installing ruby-2.2.2... Installed ruby-2.2.2 to /home/did2/.rbenv/versions/2.2.2
インストールに成功しました。
Ruby on Rails のインストール
「gem」コマンドが使えるはずなので、次のコマンドで、railsをインストールできます(マニュアルのRailsの項)。
gem install rails Fetching: i18n-0.7.0.gem (100%) ERROR: While executing gem ... (Errno::EACCES) Permission denied - /var/lib/gems
sudoを忘れました。もう一度実行します。
sudo gem install rails Fetching: i18n-0.7.0.gem (100%) ERROR: While executing gem ... (Errno::EACCES) Permission denied - /var/lib/gems did2@did2-UbuntuDesktopG1:~$ sudo gem install rails [sudo] password for did2: Fetching: i18n-0.7.0.gem (100%) Fetching: json-1.8.3.gem (100%) Building native extensions. This could take a while... Fetching: thread_safe-0.3.5.gem (100%) Fetching: tzinfo-1.2.2.gem (100%) Fetching: minitest-5.7.0.gem (100%) Fetching: activesupport-4.2.3.gem (100%) Fetching: rack-1.6.4.gem (100%) Fetching: rack-test-0.6.3.gem (100%) Fetching: mini_portile-0.6.2.gem (100%) Fetching: nokogiri-1.6.6.2.gem (100%) Building native extensions. This could take a while... Fetching: loofah-2.0.2.gem (100%) Fetching: rails-html-sanitizer-1.0.2.gem (100%) Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%) Fetching: rails-dom-testing-1.0.6.gem (100%) Fetching: builder-3.2.2.gem (100%) Fetching: erubis-2.7.0.gem (100%) Fetching: actionview-4.2.3.gem (100%) Fetching: actionpack-4.2.3.gem (100%) Fetching: activemodel-4.2.3.gem (100%) Fetching: arel-6.0.2.gem (100%) Fetching: activerecord-4.2.3.gem (100%) Fetching: globalid-0.3.5.gem (100%) Fetching: activejob-4.2.3.gem (100%) Fetching: mime-types-2.6.1.gem (100%) Fetching: mail-2.6.3.gem (100%) Fetching: actionmailer-4.2.3.gem (100%) Fetching: rake-10.4.2.gem (100%) Fetching: thor-0.19.1.gem (100%) Fetching: railties-4.2.3.gem (100%) Fetching: bundler-1.10.5.gem (100%) Fetching: sprockets-3.2.0.gem (100%) Fetching: sprockets-rails-2.3.2.gem (100%) Fetching: rails-4.2.3.gem (100%) Successfully installed i18n-0.7.0 Successfully installed json-1.8.3 Successfully installed thread_safe-0.3.5 Successfully installed tzinfo-1.2.2 Successfully installed minitest-5.7.0 Successfully installed activesupport-4.2.3 Successfully installed rack-1.6.4 Successfully installed rack-test-0.6.3 Successfully installed mini_portile-0.6.2 Successfully installed nokogiri-1.6.6.2 Successfully installed loofah-2.0.2 Successfully installed rails-html-sanitizer-1.0.2 Successfully installed rails-deprecated_sanitizer-1.0.3 Successfully installed rails-dom-testing-1.0.6 Successfully installed builder-3.2.2 Successfully installed erubis-2.7.0 Successfully installed actionview-4.2.3 Successfully installed actionpack-4.2.3 Successfully installed activemodel-4.2.3 Successfully installed arel-6.0.2 Successfully installed activerecord-4.2.3 Successfully installed globalid-0.3.5 Successfully installed activejob-4.2.3 Successfully installed mime-types-2.6.1 Successfully installed mail-2.6.3 Successfully installed actionmailer-4.2.3 Successfully installed rake-10.4.2 Successfully installed thor-0.19.1 Successfully installed railties-4.2.3 Successfully installed bundler-1.10.5 Successfully installed sprockets-3.2.0 Successfully installed sprockets-rails-2.3.2 Successfully installed rails-4.2.3 33 gems installed Installing ri documentation for i18n-0.7.0... Installing ri documentation for json-1.8.3... Installing ri documentation for thread_safe-0.3.5... Installing ri documentation for tzinfo-1.2.2... Installing ri documentation for minitest-5.7.0... Installing ri documentation for activesupport-4.2.3... Installing ri documentation for rack-1.6.4... Installing ri documentation for rack-test-0.6.3... Installing ri documentation for mini_portile-0.6.2... Installing ri documentation for nokogiri-1.6.6.2... Installing ri documentation for loofah-2.0.2... Installing ri documentation for rails-html-sanitizer-1.0.2... Installing ri documentation for rails-deprecated_sanitizer-1.0.3... Installing ri documentation for rails-dom-testing-1.0.6... Installing ri documentation for builder-3.2.2... Installing ri documentation for erubis-2.7.0... Installing ri documentation for actionview-4.2.3... Installing ri documentation for actionpack-4.2.3... Installing ri documentation for activemodel-4.2.3... Installing ri documentation for arel-6.0.2... Installing ri documentation for activerecord-4.2.3... Installing ri documentation for globalid-0.3.5... Installing ri documentation for activejob-4.2.3... Installing ri documentation for mime-types-2.6.1... Installing ri documentation for mail-2.6.3... Installing ri documentation for actionmailer-4.2.3... Installing ri documentation for rake-10.4.2... Installing ri documentation for thor-0.19.1... Installing ri documentation for railties-4.2.3... Installing ri documentation for bundler-1.10.5... Installing ri documentation for sprockets-3.2.0... Installing ri documentation for sprockets-rails-2.3.2... Installing ri documentation for rails-4.2.3... file 'lib' not found Installing RDoc documentation for i18n-0.7.0... Installing RDoc documentation for json-1.8.3... Installing RDoc documentation for thread_safe-0.3.5... Installing RDoc documentation for tzinfo-1.2.2... Installing RDoc documentation for minitest-5.7.0... Installing RDoc documentation for activesupport-4.2.3... Installing RDoc documentation for rack-1.6.4... Installing RDoc documentation for rack-test-0.6.3... Installing RDoc documentation for mini_portile-0.6.2... Installing RDoc documentation for nokogiri-1.6.6.2... Installing RDoc documentation for loofah-2.0.2... Installing RDoc documentation for rails-html-sanitizer-1.0.2... Installing RDoc documentation for rails-deprecated_sanitizer-1.0.3... Installing RDoc documentation for rails-dom-testing-1.0.6... Installing RDoc documentation for builder-3.2.2... Installing RDoc documentation for erubis-2.7.0... Installing RDoc documentation for actionview-4.2.3... Installing RDoc documentation for actionpack-4.2.3... Installing RDoc documentation for activemodel-4.2.3... Installing RDoc documentation for arel-6.0.2... Installing RDoc documentation for activerecord-4.2.3... Installing RDoc documentation for globalid-0.3.5... Installing RDoc documentation for activejob-4.2.3... Installing RDoc documentation for mime-types-2.6.1... Installing RDoc documentation for mail-2.6.3... Installing RDoc documentation for actionmailer-4.2.3... Installing RDoc documentation for rake-10.4.2... Installing RDoc documentation for thor-0.19.1... Installing RDoc documentation for railties-4.2.3... Installing RDoc documentation for bundler-1.10.5... Installing RDoc documentation for sprockets-3.2.0... Installing RDoc documentation for sprockets-rails-2.3.2... Installing RDoc documentation for rails-4.2.3... file 'lib' not found
かなり時間がかかりました。
とりあえず気になるのが「file 'lib' not found」です。詳細のわからないエラーメッセージです。
ちなみに、そのままもう一度「sudo gem install rails」すると、次のようになります。
$ sudo gem install rails [sudo] password for did2: Successfully installed rails-4.2.3 1 gem installed Installing ri documentation for rails-4.2.3... file 'lib' not found Installing RDoc documentation for rails-4.2.3... file 'lib' not found
繰り返されます。
ここで、「installation - rails 3 install error "File not found: lib"」を参考に、「gem install rdoc」を実行してから、もう一度インストールしてみます。
$ sudo gem install rdoc Fetching: rdoc-4.2.0.gem (100%) Depending on your version of ruby, you may need to install ruby rdoc/ri data: <= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install >= 1.9.2 : nothing to do! Yay! Successfully installed rdoc-4.2.0 1 gem installed Installing ri documentation for rdoc-4.2.0... Installing RDoc documentation for rdoc-4.2.0... (eval):3: warning: string literal in condition (eval):2: warning: string literal in condition
$ sudo gem install rails Successfully installed rails-4.2.3 1 gem installed Installing ri documentation for rails-4.2.3... Installing RDoc documentation for rails-4.2.3...
これで無事、RubyとRuby on Railsのインストールが終わりました。
スポンサーリンク
スポンサーリンク