How to create a Ruby environment with Vagrant

Posted in ruby, blog on November 4, 2020 by Henk Verlinde ‐ 2 min read

How to create a Ruby environment with Vagrant

Introduction

When creating your Ruby environment, we recommend using Vagrant as it is easy to distribute and back up. things to do

  1. Installing VirtualBox
  2. Install the virtualization software VirtualBox.
  3. The version used is 6.0.8 Install VirtualBox from official site

Installing Vagrant

Install Vagrant, a command tool that makes it easy to use VirtualBox’s settings and features. The version used is 2.2.5 Install Vagrant from official site

Create Linux environment

Create an environment using the Vagrant command. Enter the following in the command line tool: You can also use the command prompt that comes standard with Windows.

# create working folder
C:\Users\> mkdir ruby_env
# move to working folder
C:\Users\> cd ruby_env
# create vagrant file
C:\Users\ruby_env> vagrant init bento/ubuntu-18.04
# create environment and start
C:\Users\ruby_env> vagrant up
# SSH login to the environment
C:\Users\ruby_env> vagrant ssh 

RVM installation

Install the Ruby version control tool RVM. You can install Ruby as it is, but it’s better to be flexible about changing the Ruby version. After logging into the environment via SSH, execute the following. Reference

gpg key retrieval official

vagrant@vagrant:~$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Install RVM [stable]

vagrant@vagrant:~$ \curl -sSL https://get.rvm.io | bash -s stable --ruby

If you just installed it, RVM cannot be used, so please execute the following and reboot.

environment logout

vagrant@vagrant:~$exit

Restart VirtualBox

C:\Users\ruby_env> vagrant reload

SSH login again and install the latest ruby ​​with RVM command.

SSH login to the environment

C:\Users\ruby_env> vagrant ssh

Install latest stable ruby

vagrant@vagrant:~$rvm install ruby ​​--latest

environment logout

vagrant@vagrant:~$ exit

Restart VirtualBox

C:\Users\ruby_env> vagrant reload

The environment is now complete. Enter the environment again and try executing the ruby ​​command.

at the end

Execute the following command to check ruby.

SSH login to the environment

C:\Users\ruby_env> vagrant ssh

Check Ruby version

vagrant@vagrant:~$ ruby ​​--version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

that’s all.