[LINUX] Relationship between Homebrew + rbenv + ruby-build (Part 1)

Introduction

Recently I was thinking of changing ruby ​​management from rbenv to installing rbenv via anyenv. The main reason is that you can keep your files clean as you only have to put the path of anyenv in .zshrc ( .bash_profile for those who use bash). When I was investigating the migration method, I felt that I didn't understand rbenv well, so I decided to write an article. Also, this article assumes "when installed with homebrew ".

Where is the one installed by brew?

First of all, I didn't understand such a basic thing either. The one installed by homebrew is now in / usr/local/Celler. I thought, "I've never passed the path to/usr/local/Celler! ", But according to the homebrew mechanism, I put the appropriate version of the executable file from/usr/local/bin. It seems that a symbolic link (shortcut) is created. In other words, if the path to / usr/local/bin is in place, the commands installed by homebrew can be used. It looks like the following.

$ ll /usr/local/bin/{rbenv,ruby-build}
lrwxr-xr-x  1 shuntagami  admin    31B  8  3 15:26 /usr/local/bin/rbenv -> ../Cellar/rbenv/1.1.2/bin/rbenv
lrwxr-xr-x  1 shuntagami  admin    44B 12 20 08:13 /usr/local/bin/ruby-build -> ../Cellar/ruby-build/20201210/bin/ruby-build

By the way, PATH is set in the environment variable $ PATH, and you can check it with echo $ PATH. Below is my example.

$ echo $PATH
/Users/shuntagami/.anyenv/envs/nodenv/shims:/Users/shuntagami/.anyenv/envs/nodenv/bin:/Users/shuntagami/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

The paths are separated by : so it's easy to see.

$ echo $PATH
/Users/shuntagami/.anyenv/envs/nodenv/shims
/Users/shuntagami/.anyenv/envs/nodenv/bin
/Users/shuntagami/bin
/usr/local/bin 
/usr/bin
/bin
/usr/sbin
/sbin

You have the path to / usr/local/bin! As a side note, if $ PATH has the same path, you can solve it with typeset -U path PATH.

There are a lot of bins, but what do you mean?

The environment variable $ PATH mentioned earlier had/usr /,/bin etc., but I will explain the difference between them. In the first place, bin is a Binary code, which means that it is a place for executable programs. Since commands are actually programs, they are saved separately according to authority and usage.

/bin Place commands that are also available in single user mode. To put it the other way around, commands located in "/ usr/bin" and "/ usr/local/bin" cannot be used in single-user mode. Single-user mode is basically used in an emergency such as when the OS is broken and cannot be started normally, so "/ bin" will contain very basic commands to be used in an emergency.

/sbin Commands for system administration are stored here. Many system administration commands are run as the root user (after becoming an administrator).

/usr/bin In/usr/bin, "not used in single user mode" and "commands and programs managed by the package management system such as RPM and deb" are placed. Although not used in an emergency, important commands and programs that make up the system will be placed here. Also, there are over 1000 commands here, so it's easy to check using the ls -l/usr/bin | less command.

/usr/sbin Similar to the difference between/bin and/usr/bin.

/usr/local/bin / usr/local/bin is used to store your own installed commands or your own commands.

Summary

I explained that the program installed by brew goes into the/usr/local/Celler directory etc. and the path can be passed by creating a symbol link, and each directory structure. In Part 2 , we will actually install rbenv and ruby-build and explain the details!

reference

Use the "/ bin", "/ usr/bin", and "/ usr/local/bin" directories properly https://linuc.org/study/knowledge/544/

Linux standard textbook https://linuc.org/textbooks/linux/

Recommended Posts

Relationship between Homebrew + rbenv + ruby-build (Part 1)
Relationship between Controller and View
Relationship between package and class