Ruby
Rails
Ubuntu
vagrant

VagrantでUbuntuにRails環境をつくる

More than 3 years have passed since last update.

いままでcentosを使っていたのですが、ココを眺めていたら
https://atlas.hashicorp.com/boxes/search

あれ、「ubuntu/trusty64」が圧倒的に流行っている...。Ubuntu良いと聞くし、語源も「思いやり」らしいし。これはUbuntuで開発してみよう。yumじゃなくてapt-getだ!

Add vagrant box

vagrant box add ubuntu/trusty64
vagrant box list
cd
mkdir project
cd project
vagrant init ubuntu/trusty64
vagrant up
vagrant ssh

Install latest git

1.4 使い始める - Gitのインストール

vagrant ssh
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
cd
wget https://www.kernel.org/pub/software/scm/git/git-2.5.0.tar.gz
tar -zxf git-2.5.0.tar.gz
cd git-2.5.0
make prefix=/usr/local all
sudo make prefix=/usr/local install
which git
sudo su -
git --version

Install ruby from rbenv

vagrant ssh
cd
sudo apt-get install -y libreadline-dev
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo $SHELL
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
which rbenv
rbenv --version
rbenv install --list
rbenv install 2.2.2
rbenv versions
rbenv global 2.2.2
rbenv rehash
rbenv version
which ruby
ruby -v
which gem 
gem -v

Install rails from gem & rails new

vagrant ssh
cd
sudo apt-get -y install libxslt-dev libxml2-dev libsqlite3-dev
echo install: --no-rdoc --no-ri >> .gemrc
echo update:  --no-rdoc --no-ri >> .gemrc
gem list
gem install rails
which rails
rails -v
cd /vagrant
rails new first_app
cd first_app

Edit Vagrantfile

Uncommentout and change port

config.vm.network "forwarded_port", guest: 3000, host: 3005

Edit Gemfile

Uncomment out

gem 'therubyracer', platforms: :ruby

rails s

apt-cache search g++ | grep g++
sudo apt-get install -y g++
cd /vagrant/first_app
bundle update
bundle install
rails s -b 0.0.0.0

Completed !

Access localhost:3005, then...

スクリーンショット 2015-08-23 12.15.45.png

追記

./bin/rails dbが動かないからsudo apt-get install -y sqlite3もしておきました。