DEV Community

wind-up-bird
wind-up-bird

Posted on

Preparation of getting start "Ruby on Rails Tutorial"

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Second, I installed rbenv plugin.

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

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]
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
$ rails -v
Rails 5.1.6
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

After that, I accessed this URL;

http://localhost:3000

Screenshot.png

;)

Top comments (0)