[RAILS] How to build an environment for any version of Ruby using rbenv

This article will show you how to build any version of Ruby environment using rbenv.

What is rbenv?

rbenv ** is a tool ** that manages different versions of ruby collectively.

By using rbenv, you can centrally manage different versions of ruby, In addition, you can switch to any version at any time. You can use Ruby with any version.

For example, when I am advancing self-learning, for example, some teaching materials say that I use ruby 2.5.2. If you are instructed to use ruby 2.7.0 in another material, the difference between versions may cause an error and get stuck.

By using rbenv, you can always use your favorite version. At the very least, errors due to differences between versions can be suppressed.

rbenv setup

Now let's actually set up rbenv.

Install rbenv

rbenv can be installed with HomeBrew. Hit the following command.

$ brew install rbenv

Initial setting of rbenv

After installing rbenv, enter rbenv init for initial setup.

$ rbenv init

When you enter and press Enter, the following instructions will be displayed. Follow the instructions. Here we are telling you to add the line eval ~ to ~ / .bash_profile.

$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

Open .bash_profile with the vi command and add eval ~ to the end.

$ vi ~/.bash_profile

When you have finished saving, quit the terminal and reopen it. You can now use rbenv from anywhere.

Testing rbenv

Then run the following command to check if rbenv is working properly. (Introduced on the official website of rbenv))

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20170523)
Counting installed Ruby versions: none
  There aren't any Ruby versions installed under `~/.rbenv/versions'.
  You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK

If everything is OK, as in the example above, rbenv is ready.

Ruby setup

Now that you can version control Ruby with rbenv, let's install Ruby.

Install Ruby with rbenv

Enter rbenv install xxxx to install Ruby. This time, I will install the latest stable version, ruby 2.7.0, at the time of writing.

$ rbenv install 2.7.0

Check the list of installed Ruby

Enter rbenv version to see the installed version.

$ rbenv versions
  system
* 2.5.1 (set by /Users/xxxxxx/.rbenv/version)
  2.6.3
  2.7.0

The version marked with * is the version of ruby you are currently using. This means that 2.7.0 is just installed and hasn't switched yet.

Version switching

Use the rbenv global command to switch to the installed 2.7.0.

$ rbenv global 2.7.0

Enter ruby -v to see which Ruby version you are using.

$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]

Since 2.7.0 is displayed, I was able to successfully install ruby 2.7.0 and build the environment.

Recommended Posts

How to build an environment for any version of Ruby using rbenv
[Rails] How to build an environment with Docker
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
How to build docker environment with Gradle for intelliJ
[Ruby] How to use rbenv (version `x.x.x'is not installed)
I tried to build an environment using Docker (beginner)
An unsupported Java version How to get rid of errors
What happened in "Java 8 to Java 11" and how to build an environment
[2020 version] How to send an email using Android Studio Javamail
How to deal with different versions of rbenv and Ruby
How to install ruby through rbenv
[Ruby] How to use any? Method
How to build CloudStack using Docker
How to get the contents of Map using for statement Memorandum
How to publish an application using AWS (3) EC2 instance environment construction
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
[Ruby] How to use slice for beginners
How to build Rails 6 environment with Docker
Build an environment of "API development + API verification using Swagger UI" with Docker
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Environment construction of Ruby on Rails from 0 [Cloud9] (From Ruby version change to Rails installation)
How to solve the local environment construction of Ruby on Rails (MAC)!
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[For Rails beginners] Summary of how to use RSpec (get an overview)
[Ruby On Rails] How to search the contents of params using include?
How to insert processing with any number of elements in iterative processing in Ruby
How to find the cause of the Ruby error
[App development 1] [Node.js express Docker] Build an environment for Node.js Express MongoDB (mongoose) using Docker [December 2020]
How to use an array for HashMap keys
Manage the version of Ruby itself with rbenv
[Error resolution] Occurs when trying to build an environment for spring with docker
Install an older version of Docker for Mac
Rails6.0 ~ How to create an eco-friendly development environment
[Ruby on Rails] Let's build an environment on mac
How to build a Pytorch environment on Ubuntu
How to build the simplest blockchain in Ruby
How to build an executable jar in Maven
How to specify index of JavaScript for statement
How to implement Pagination in GraphQL (for ruby)
How to use git with the power of jgit in an environment without git commands
How to request by passing an array to the query with HTTP Client of Ruby
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
How to install Ruby on an EC2 instance on AWS
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
How to build Docker + Springboot app (for basic learning)
How to use an array for a TreeMap key
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
[Ruby] How to find the sum of each digit
Build ruby debug environment with VS Code of Windows 10
How to build Java development environment with VS Code
How to judge the click of any area of the image
How to boot by environment with Spring Boot of Maven
How to download the old version of Apache Tomcat
Try to build a Java development environment using Docker
How to execute WebCamCapture sample of NyARToolkit for Java
[2021] Build a Docker + Vagrant environment for using React / TypeScript
How to use rbenv
How to build android-midi-lib
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
How to change Java version and execute in an environment where Java cannot be installed freely