This article will show you how to build any version of Ruby environment using 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.
Now let's actually set up rbenv.
rbenv can be installed with HomeBrew. Hit the following command.
$ brew install 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.
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.
Now that you can version control Ruby with rbenv, let's install Ruby.
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
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.
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.