loading...

Preparation of getting start "Ruby on Rails Tutorial"

windupbird profile image wind-up-bird ・2 min read

Background

These days, I started studying Rails with Ruby on Rails Tutorial in Japanese.
(This is Japanese version)

I set up the local environment with Vagrant and VirtualBox because I don't want to use AWS and Heroku etc... (The main reason is money.)

So I write down the article (or note?) to start Ruby on Rails Tutorial.

My Environment

  • OS: macOS High Sierra (version 10.13.6)
  • Vagrant: 2.2.0
  • VirtualBox: 5.2.18

Please see below how to install Vagrant and VirtualBox if you do not installed yet.
Downloads – Oracle VM VirtualBox
Installing Vagrant - Vagrant by HashiCorp

Vagrantfile

I used Ubuntu 18.04 as guest Virtual Machine.
And I set the port forwarding from 3000 (host) to 3000 (guest).

Example

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.provider "virtualbox" do |vb|
     vb.memory = "2048"
  end
end

In my case, the error occurred because of the lack of memory when I install rails on guest VM. So, I changed the size of memory (default is 1024 I guess) as above.

Install rbenv

After launching VM,

$ vagrant up
$ vagrant ssh

I installed rbenv first.

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ rbenv -v
rbenv 1.1.1-39-g59785f6

Second, I installed rbenv plugin.

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Install Ruby

Then, I checked the version of Ruby and installed 2.5.0.

$ rbenv install --list
$ rbenv install 2.5.0
$ rbenv rehash
$ rbenv global 2.5.0
$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]

By the way, I found some errors in this procedure because essential packages were not installed. So, I did development tools etc.

$ sudo apt update
$ sudo apt install build-essential
$ sudo apt install libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev nodejs

Install rails

In Ruby on Rails Tutorial, Rails version is 5.1.6, so I run this command;

$ gem install rails -v 5.1.6
$ rails -v
Rails 5.1.6

Seems success to install.

First Rails application

I want to check whether the installation was correct, so run these commands;

$ mkdir environment
$ cd environment/
$ rails _5.1.6_ new hello_app
$ cd hello_app/
$ rails server

After that, I accessed this URL;

http://localhost:3000

Screenshot.png

;)

Posted on by:

Discussion

markdown guide