みそしりんぐ

現在進行形みそしる

Vagrant × Ruby

いろいろできずに困っていたものが,理由もわからずできるようになったのでまとめ.
Vagrantなんかは相当前に入れたのでどうやって自分が導入したのかいまいち記憶にありませんがそこはいろいろで補いつつ.

Vagrant

Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the "works on my machine" excuse a relic of the past.
Vagrant

目次

  1. Vagrant
    • 導入
    • Vagrantのコマンドたち
  2. Ruby + Ruby on Rails
  3. 参考

Vagrant

導入

とりあえず上の2つをインストール.
boxはvagrantbox.esから.私が入れたのは,CentOS 6.5 x86_64.
list出力してきちんと出てくれば完了です.
(私はコピペした際にうっかりcentos65-x86_64-20140116のままにしちゃいましたが短くしといたほうがあとで便利な気がします)

$ vagrant box add centos65-x86_64-20140116 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
$ vagrant box list

作業ディレクトリを作成し,そこに移動後以下を行います.

$ vagrant init centos65-x86_64-20140116
$ vagrant up
$ vagrant ssh

こんな感じで起動,SSH接続でシェルにアクセスできました.

Vagrantのコマンドたち
$ vagrant -h

$ vagrant status // ステータス表示,以下は起動しているとき
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

$ vagrant ssh // マシンにSSH接続
$ vagrant suspend // 保留
$ vagrant resume // 再開
$ vagrant up // 起動
$ vagrant halt // シャットダウン
$ vagrant reload // 再起動
$ vagrant destroy // 停止・削除

Ruby + Ruby on Rails

準備
$ sudo yum -y install git
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Git,ればにらを入れます.
rbenvをればにらなんて呼ぶのは私だけだと思いますが見えてしまったものはしょうがない.

パス通し..bash_profileをみれば書き込まれたのがわかると思います.

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

ruby-build

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Ruby
$ yum install gcc make openssl-devel
$ rbenv install 2.0.0p481
$ rbenv global 2.0.0p481

$ ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
Ruby on Rails
$ gem update --system
$ gem install rails --no-ri --no-rdoc -V
$ rbenv rehash

$ rails -v
Rails 4.1.1