Relationship between Homebrew + rbenv + ruby-build (Part 2) You can actually introduce ruby ​​and Rails!

In the previous article , the program installed by brew enters the / usr/local/Celler directory etc. and creates a symbol link. I explained that the path can be passed by doing, and each directory structure. This time, I will actually install rbenv and ruby-build and explain what each command is doing.

Installation of rbenv, ruby-build

First, keep brew up to date.

% brew update

Next is the installation of rbenv and ruby-build. ruby-build is one of the rbenv plugins. It provides a command to install the Ruby version called rbenv install. When installing rbenv, install it as a set.

% brew install rbenv ruby-build

What is RBENV_ROOT?

I will explain this term because it is necessary for the explanation of the next command. RBENV_ROOT is an environment variable that points to the location (path) of rbenv's shims (described later) and versions (where Ruby is installed). By default, it is directly under your home directory, and you can check it as follows.

% rbenv root
/Users/shuntagami/.rbenv

rbenv init entity

Return the story. According to rbenv installation procedure , the following command should be executed.

% echo 'eval "$(rbenv init -)"' >> ~/.zshrc  #(`~/.zshrc`Please change the part according to the shell you are using.)

What does this do? The answer is, as written, enable shims and autocompletion. Let's check what is in shims.

% cd .rbenv
% ls
shims    version  versions

% cd shims
% ls
bundle bundler erb gem irb rake rdoc ri ruby testrb,,,

It contains commands that are familiar to anyone who has used bundle, rake, or rails. This means that by enabling shims, you can put $ RBENV_ROOT/shims in PATH and these commands can be used from anywhere. Finally, let's read the changes in the shell configuration file with the following command.

source ~/.zshrc  #(`~/.zshrc`Please change the part according to the shell you are using.)

Install ruby ​​with rbenv

Now that the installation of rbenv is complete, we will install ruby. Check the installable version as follows.

% rbenv install --list

Install the latest version unless you have a specific reason.

% rbenv install 2.7.2

Run the following command to use the installed version.

% rbenv global 2.7.2

Finally, load rbenv to reflect the changes. Make sure to run it when you install a new version of Ruby or after you install the gem that provides the executable.

% rbenv rehash

Prepare Rails

Since the introduction of ruby ​​is over, I will explain the installation procedure of Rails.

Install bundler

A bundler is a gem that manages gem versions and gem dependencies. By using bundler, you can develop with multiple people or even if the gem version goes up without causing an error.

% gem install bundler

The bundler itself is also a gem, so you should see 1 gem installed when the installation is complete.

Rails installation

% gem install rails --version='6.0.0'

Specify the version to install. When you're done, run the rbenv rehash command described earlier.

reference

How rbenv + ruby-build works https://takatoshiono.hatenablog.com/entry/2015/01/09/012040

rbenv official https://github.com/rbenv/rbenv#basic-github-checkout

Summary

We looked at the installation procedure of ruby ​​and Rails and the meaning of each command. After that, if you install the database, yarn, Node.js, you will be able to run Rails.

Recommended Posts

Relationship between Homebrew + rbenv + ruby-build (Part 2) You can actually introduce ruby ​​and Rails!
[Ruby vs Python] Benchmark comparison between Rails and Flask
Summary of Differences Between Ruby on Rails and Django ~ Basics ~