Manage multiple versions of Ruby on Mac [macOS + rbenv]

Introduction

I had never touched Ruby, so I decided to try it again and built a Ruby environment on my Mac. Ruby is installed as standard on Mac, but the version is old, so if you install the latest version anyway, it is the same as PHP's phpenv I thought that it would be easier to switch between multiple versions of Ruby by inserting rbenv, so I wrote this article.


environment


Purpose

Manage multiple versions of Ruby on your Mac and switch between them so you can use them. (The version is different for each project)


rbenv installation procedure

First, Homebrew update

$ brew update

Then install rbenv

$ brew install rbenv
...
Error: Permission denied @ apply2files - /usr/local/lib/node_modules/cordova/node_modules/extglob/lib/.DS_Store

I got a permission error in my environment, but Ignore it because it's from .DS_Store

Finally check the version of rbenv

$ rbenv --version
rbenv 1.1.2-11-gc46a970

This completes the installation! It's too easy to beat. I only remember that it was more troublesome when I introduced PHP's phpenv. .. ..


bonus

You can get help by running the rbenv command with no arguments, but just in case.

$ rbenv
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   install     Install a Ruby version using ruby-build
   uninstall   Uninstall a specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List installed Ruby versions
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme

$ rbenv install --list-all
1.8.5-p52
1.8.5-p113
1.8.5-p114
...
$ rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
ruby-build: using readline from homebrew
Installed ruby-2.7.1 to /Users/XXXXX/.rbenv/versions/2.7.1
$ rbenv versions
* system (set by /Users/XXXXX/.rbenv/version)
  2.7.1

* System is Ruby originally installed on Mac
$ rbenv version
system (set by /Users/XXXXX/.rbenv/version)
$ rbenv local 2.7.1
$ruby global 2.7.1

Various commands and the operation of each command are the same as phpenv. So if you have used phpenv, you may be able to use it without any discomfort.

Recommended Posts

Manage multiple versions of Ruby on Mac [macOS + rbenv]
Switch between multiple versions of Java on Mac
Manage the version of Ruby itself with rbenv
Switch between multiple versions of Java on Mac
How to switch between multiple Java versions
How to deal with different versions of rbenv and Ruby
Install ruby on Ubuntu 20.04 with rbenv
How to solve the local environment construction of Ruby on Rails (MAC)!
[Ruby on Rails] Introduction of initial data
[Rails] Addition of Ruby On Rails comment function
Directory information of DEFAULT_CERT_FILE in Mac ruby 2.0.0
Ruby on Rails installation method [Mac edition]
Let's summarize "MVC" of Ruby on Rails
part of the syntax of ruby ​​on rails
How to switch Java versions on Mac
[Ruby on Rails] Japanese notation of errors
Explanation of Ruby on rails for beginners ①
Uncertainty of common Jar for multiple versions
Open multiple workspaces in Eclipse on Mac
Use jenv to enable multiple versions of Java
Implementation of Ruby on Rails login function (Session)
[Ruby on Rails] Until the introduction of RSpec
Easily switch Java versions with alias on macOS
Building a Ruby environment for classes on Mac
Install Ruby / Rails on Mac M1 Big Sur 2021-01
Ruby on Rails ~ Basics of MVC and Router ~
[Ruby on Rails] A memorandum of layout templates
[Ruby on Rails] Let's build an environment on mac
rbenv versions and ruby -v versions do not match
[Ruby on Rails] Upload multiple images with refile
[Ruby on Rails] Individual display of error messages