ツヨシのブログ

技術的な事とか日常の事とか徒然なるままに

スポンサーリンク

vagrantでrailsの環境とHerokuのインストールの忘備録

スポンサーリンク

vagrantrailsの環境とHerokuのインストールの忘備録です。qiitaにも投稿済み。

vagrantでrailsの環境とHerokuのインストールの忘備録 - Qiita

Vagrantの環境構築

vagrant box

まずはvagrantのboxの導入。ubuntuを使用したかったので、次のvagrant boxを使用した。Vagrant cloud便利!!!

https://vagrantcloud.com/hashicorp/boxes/precise64

vagrantの実行

vagrantの環境を整えるために以下を実行した。

mkdir precise64
cd precise64
vagrant init hashicorp/precise64
vagrant up
vagrant ssh

Vagrant仮装環境へのtoolbelt/railsのインストール

heroku toolebeltのインストール

herokuの開発を簡単にするため、heroku toolbeltをインストールした。

sudo wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

仮装環境でのrailsのインストール

railsも必要なのでrailsインストールのために以下を実行。

sudo gem install rails

ERRORが出力

railsインストール中に以下のエラーが出力された。jsonがインストールされていない?? 色々と調べるうちにrubyのヘッダファイルや、開発環境などがインストールされていないようだ。

vagrant@precise64:~$ sudo gem install rails
Fetching: i18n-0.6.11.gem (100%)
Fetching: json-1.8.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

対応

対応としては次のコマンドにより、諸々インストール。これによりrailsのインストールも無事成功!!!

sudo apt-get install ruby1.9.1-dev
sudo apt-get install build-essential
sudo gem install json

参照

http://stackoverflow.com/questions/20487820/ember-js-error-gem-install-json-v-1-8-1-succeeds-before-bundling-while-bu

追記1

railsのアプリを作成しようとしたら怒られた

以下のコマンドを実行した。

rails new first_app

エラー内容

エラーは以下のとおり。sqlite3が使えないようだ。sqlite3のライブラリをインストールとgemの実行をした。

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby1.9.1
    --with-sqlite3-dir
    --without-sqlite3-dir
    --with-sqlite3-include
    --without-sqlite3-include=${sqlite3-dir}/include
    --with-sqlite3-lib
    --without-sqlite3-lib=${sqlite3-dir}/lib
    --enable-local
    --disable-local


Gem files will remain installed in /tmp/bundler20140927-6701-1g6azeg/sqlite3-1.3.9/gems/sqlite3-1.3.9 for inspection.
Results logged to /tmp/bundler20140927-6701-1g6azeg/sqlite3-1.3.9/gems/sqlite3-1.3.9/ext/sqlite3/gem_make.out
An error occurred while installing sqlite3 (1.3.9), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.9'` succeeds before bundling.
         run  bundle exec spring binstub --all
/var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/resolver.rb:357:in `resolve': Could not find gem 'sqlite3 (>= 0) ruby' in the gems available on this machine. (Bundler::GemNotFound)
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/resolver.rb:164:in `start'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/resolver.rb:129:in `resolve'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/definition.rb:193:in `resolve'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/definition.rb:132:in `specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/definition.rb:177:in `specs_for'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/definition.rb:166:in `requested_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/environment.rb:18:in `requested_specs'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/runtime.rb:13:in `setup'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler.rb:121:in `setup'
    from /var/lib/gems/1.9.1/gems/bundler-1.7.3/lib/bundler/setup.rb:17:in `<top (required)>'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

対応

次のコマンドを実行した。その後無事railsが走った。

sudo apt-get install libsqlite3-dev
sudo gem install sqlite3 -v '1.3.9'

追記2

後日Windows7vagrant boxをインストールしようとしたら怒られた。

内容

c:\test\vagrant\precise64>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["list", "hostonlyifs"]

Stderr: VBoxManage.exe: error: Failed to create the VirtualBox object!
VBoxManage.exe: error: Code E_NOINTERFACE (0x80004002) - No such interface suppo
rted (extended info not available)
VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or
failed to start.

対応

どうやらVirtualBoxの実行の際にWindows Vista互換モードで実行する必要があるようだ。 プログラムを右クリックでプロパティを表示して、互換モードのタブで「Windows Vista (Service Pack 2)」で管理者権限で実行するように変更した。

参照

Vagrant and Virtualbox problems on Windows 7 - Solar Polar