This article is an article that explains how to build a Ruby on Rails environment so that even beginners can do it without hesitation.
Ruby on Rails is used in extensive development. It is often adopted by Japanese startups, and tabelog, note, accounting software freee, etc. are also developed by Ruby on Rails.
For such Ruby on Rails, version 6.0 was released in August 2019, and version 6.1 was released in December 2020. In addition, Ruby itself has undergone a major update to version 3.0 in December 2020, adding new features.
Here, we will explain how to build an environment for ** Ruby 3.0 and Ruby on Rails 6.1.1 **.
--Cloud9 (Compatible with both Mac and Windows) --Article on how to build an environment on Mac is also available.
Sign in to the console from the URL below and launch Cloud9.
https://us-east-2.console.aws.amazon.com/console/
Launch Terminal on Cloud9 and execute the following command to check the Ruby version.
ruby -v
The numbers are displayed as shown below.
ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
Here you can see that the Ruby environment is "** 2.6.3 **".
Now let's change the Ruby version from here.
Use rvm, a Ruby version control tool.
Check the installed Ruby version with the following command.
rvm list
The execution result is as follows.
rvm list
=* ruby-2.6.3 [ x86_64 ]
# => - current
# =* - current && default
# * - default
It also lists the Ruby versions that can be installed with the following command.
rvm list known
Check the execution result to confirm that you have the version you want to install.
rvm list known
//====Abbreviation====
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
ruby-head
//====Abbreviation====
If you don't have the version you want to install here, you'll need to update rvm.
To update, execute the get
command as shown below.
rvm get latest
rvm get latest
//====Abbreviation====
Thanks for installing RVM
Please consider donating to our open collective to help us maintain RVM.
Donate: https://opencollective.com/rvm/donate
RVM reloaded!
Check the version of rvm you have installed.
rvm -v
rvm 1.29.10 (1.29.10) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
Make sure you have the version you want to install again.
rvm list known
//====Abbreviation====
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0] #← Version you want to install
ruby-head
//====Abbreviation====
Then run the following command to install the Ruby version.
In the <version>
part, specify the version to install.
rvm install <version>
If the following is displayed, the installation is successful.
Here, 3.0
is specified.
rvm install 3.0
//===Abbreviation===
ruby-2.7.2 - #generating global wrappers.......
ruby-2.7.2 - #gemset created /home/ec2-user/.rvm/gems/ruby-2.7.0
ruby-2.7.2 - #importing gemsetfile /home/ec2-user/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.7.2 - #generating default wrappers.......
Let's specify the version to use with the following command.
rvm use <version>
rvm use 3.0.0
Finally, check that the version you specified earlier is displayed with the following command.
ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
This is the end of Ruby version change.
After installing Ruby, then install ** Bundler **.
Ruby uses a library called ** Gem ** to manage packages.
You can easily install and uninstall with the Gem command, but if you use multiple Gem, a dependency will be created between the Gem and problems will occur due to different versions.
Therefore, Bundler accurately tracks and manages each version of Gem to provide a consistent environment for Ruby projects.
reference:
Now let's install Bundler. Enter the following command.
gem install bundler
Run the command to start the installation.
Check the version of Blundler installed.
Enter the following command:
bundler -v
After running the command, you should see something like this:
bundler -v
Bundler version 2.1.4
"Version 2.1.4" and version information are displayed.
You have now confirmed that Blendler is installed.
Then install ** yarn **.
yarn is a package manager required to use JavaScript libraries.
There is also a package manager called npm that is compatible with yarn. However, Rails 6 requires yarn because Webpacker has become the standard.
Now let's install yarn.
Enter the following command:
npm i -g yarn
To see if yarn was actually installed, enter the following command:
yarn -v
When I run the command, I get the following:
yarn -v
1.22.10
Here, " 1.16.0
"is displayed. If the version information is displayed, you can confirm that yarn has been installed.
From here, we will check the version of Rails.
Check the Rails version by running the following command in Cloud9 Terminal.
rails -v
The Rails version specified by default is displayed as shown below.
rails -v
Rails 5.0.0
If you don't specify a version when you run rails new
, your application will be created with this version.
Next, let's check the version of Rails installed.
Execute the following command.
gem list rails
The following will be displayed, so check the ** rails ** item. You can see that "5.0.0" is installed.
gem list rails
*** LOCAL GEMS ***
rails (5.0.0)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.3.0)
sprockets-rails (3.2.2)
Finally, install Rails.
When installing Rails, you can specify the version as " -v version number
".
This time, install version " 6.1.1
".
Reference: History of all versions of rails
Enter the following command:
gem install rails -v 6.1.1
Run the command to start the installation. It may take a few minutes to complete the installation.
After installing Rails, enter the following command to check your Rails version:
rails -v
When you run the command, you will see the following screen.
rails -v
Rails 6.1.1
" Rails 6.1.1
"is displayed.
This completes the installation of Ruby on Rails.