What I stumbled upon when installing Ruby on Ubuntu

Introduction

I ran into a code while installing Ruby on Ubuntu at this site.

#Add path $ echo 'export PATH="HOME/.rbenv/bin:PATH"' >> ~/.bash_profile

#Addition of rbenv initialization script $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile


 What the hell is this ...
 At first I thought, but as I researched it, I understood it to some extent, so I will summarize it in an article so that I will not forget it.
 If you make a mistake, please let me know in the comments.

# About echo
 First, let's talk about the command ʻecho`. See [here](https://eng-entrance.com/linux-command-echo) for a detailed description of ʻecho`. There are three ways to use ʻecho` used in the first command I wrote.

>```sh
#Add the character string to the file.
$echo string>>file name

># 「$Display the string "variable".
$ echo '$variable'

># 「$Display the contents of a variable called "variable".
$ echo "$variable"

Now go back to the first code.

$ echo 'export PATH="HOME/.rbenv/bin:PATH"' >> ~/.bash_profile $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile


 Both commands have the form ʻecho string >> ~ / .bash_profile`.

 In other words, I'm adding the string to a file called .bash_profile in my home directory. This .bash_profile will be explained later.

 Regarding the contents of the string, `'export PATH =" $ HOME / .rbenv / bin: $ PATH "'`, export is a command that allows you to define environment variables. So this sets the environment variable `PATH` to the value` "$ HOME / .rbenv / bin: $ PATH" `. Environment variables will be explained later.

 Similarly, the contents of the character string are `'eval" $ (rbenv init-) "'`, but eval is a command that concatenates the specified character string after evaluation and causes the current shell to execute it. [Have a look at this. Actually, I didn't know much about eval, so I'll try to find out a little more.
 In my interpretation, this command causes the shell to execute the command `rbenv init -`.

## About .bash_profile
 The .bash_profile that came out earlier, but [this article](https://neos21.hatenablog.com/entry/2017/02/12/142817) is easy to understand.
 To summarize briefly, bash_profile is a file that runs only once at login.
 Considering it together with the previous story

>```sh
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Means to define $ HOME / .rbenv / bin: $ PATH in PATH only once at login and run rbenv init -.

About "passing through"

Next, let's talk about what it means to "pass through". In conclusion, "passing through" means

Change the description of the environment variable ($ PATH) and add the command search path.

Quoted from this site. Please read it because it has a very detailed description of "passing through".

Returning to the story, environment variables are variables stored in your personal computer. You can check the environment variables with the following command.

The name of the printenv environment variable

#If no argument is added after printenv, all environment variables will be displayed. printenv


 If you execute `printenv`, the environment variables will be displayed in a row, and you can see the environment variable` PATH` in it.

 What role this `PATH` plays is that it tells the shell (terminal) where the executable is located.

 For example, in the command `printenv` that came out earlier, the shell refers to the executable file` / usr / bin / printenv`. Therefore, the following two commands are the same.

>```sh
$ /usr/bin/printenv
$ printenv

The reason why / usr / bin can be omitted at this time is that this is described in PATH.

When you execute printenv PATH, it will be described as/ home / [user name] / bin: .... It has paths separated by: and is looking for the location of the executable in order from the first path.

Let's take a look at the first command I wrote here.

$ echo 'export PATH="HOME/.rbenv/bin:PATH"' >> ~/.bash_profile


 I told you that this command defines the value `$ HOME / .rbenv / bin: $ PATH` in` PATH`. Here, `$ HOME / .rbenv / bin: $ PATH` is enclosed in" ", so` $ HOME` and `$ PATH` refer to the values in the environment variables. The value of `$ HOME` is` / home / [user name] `in my case, and` PATH` is `/ home / [user name] / bin: ...` as before.

 That is, the value of `$ PATH` defined by ʻexport PATH =" $ HOME / .rbenv / bin: $ PATH "` is `/ home / [username] /.rbenv/bin:/home/[username] / bin: ・ ・ ・ `. This will allow the shell to reference the executable in `/ home / [username] /. Rbenv / bin`.

# Finally
 No, it was long. At first I thought it was a mess, such as passing through a path or .bash_profile, but when I looked it up, it was surprisingly interesting to understand. Now that the rails environment is in place, I would like to summarize what I learned from rails.


Recommended Posts

What I stumbled upon when installing Ruby on Ubuntu
What I stumbled upon when installing Laravel-filemanager
What I did when I stumbled on IntelliJ gradle 2.2 → 2.6 environment migration
I made a mistake when installing VLC on Ubuntu 18.04 via snap
Install Ruby on Ubuntu 20.04
What I stumbled upon in the ActiveModel :: Serializer test
Installing OpenMX on Ubuntu 18.04.5 LTS
Ruby installation on WSL2 + Ubuntu 20.04
I tried installing Ruby on Rails related plugin with vim-plug
Pit pits when installing dotnet on Ubuntu 18.04 LTS + WINE + winetricks
Beginner Ruby on Rails What I learned is being summarized
[MacOS] I was disturbed by ruby when installing Spring Boot CLI
A note when I was addicted to converting Ubuntu on WSL1 to WSL2
I tried installing CentOS 8 on ESXi 6.7
Install ruby on Ubuntu 20.04 with rbenv
Installing and using Ansible on Ubuntu 16.04
What to do when Blocked Host: "host name" appears in Ruby on Rails
What I stumbled upon when installing Laravel-filemanager
[Beginner] I stumbled upon launching a project with Rails6
Note that I stumbled upon building the Rails environment
What I stumbled upon when installing Ruby on Ubuntu
What I stumbled upon in the ActiveModel :: Serializer test
Check when nvidia-smi on Ubuntu doesn't work
Disable pop-ups when switching workspaces on Ubuntu 20.04
Microservices 101-I tried putting Docker on Ubuntu-
Points I stumbled upon when creating an Android application [Updated from time to time]
When the Ruby on Rails terminal rolls back
Error installing ruby execution environment on EC2 instance
I was addicted to installing Ruby/Tk on MacOS
What I did when I converted java to Kotlin
I tried installing docker on an EC2 instance
[Swift] Beginners stumbled upon installing CocoaPods & installation procedure
I made a portfolio with Ruby On Rails
What to do when booting Ubuntu on WSL2 and getting "Process terminated with code 1"
The story that did not disappear when I tried to delete mysql on ubuntu
[Ruby on Rails] I get a warning when running RSpec because gem'chromedriver-helper' is deprecated.
Notes on errors that occur when installing the JDK and countermeasures that I have tried