Skip to content

Set up Rails

Ryuji EGUCHI edited this page Jun 7, 2023 · 8 revisions

Install Ruby and Rails

NOTE:

  • Install brew

  • Install ruby-build and rbenv

    $ brew install ruby-build
    $ brew install rbenv
    
  • Add the following settings to .zshenv (.bash_profile for bash) in accordance with the install log.

    export PATH="$HOME/.rbenv/bin:$PATH"
    if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
    
  • Check the available versions of ruby

    $ rbenv install -l
    
  • Install readline

    $ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline)"
    

    The Japanese characters are garbled without this. (これがないと、rails console で日本語入力が化ける)

    ref: http://thr3a.hatenablog.com/entry/20160828/1472324261

  • Install ruby (The version can be changed. It should be 2.5.1 as of 2018/4/11)

    $ MAKE_OPTS="-j 4" rbenv install 2.5.1
    

    MAKE_OPTS="-j 4" is for parallel compile.

  • Set the ruby version

    $ rbenv global 2.5.1
    $ rbenv versions
      system
    * 2.5.1
    
  • Install bundler

    $ gem install bundler
    
  • Install rails

    $ gem install rails
    

Create a Rails app

$ app_name='<your_app_name>'

$ database='mysql'
# or
$ database='postgresql'
## postgresql is more common with Rails.

$ rails_version='7.0.5'
## The version depends on the project.

$ rails _${rails_version}_ new ${app_name} --database=${database} --skip-bundle --skip-test
## --skip-test is for not installing minitest because we use rspec.  
## --skip-action-cable and --skip-turbolinks are likely options.

$ cd ${app_name}

$ git init

$ git commit --allow-empty -m "initial commit"
## This is not mandatory.

$ git add .

$ git commit -m 'add rails'

$ bundle config set --local path 'vendor/bundle'

$ bundle install

  • You might think of using UUID for ID.
Clone this wiki locally