Build a Ruby on Rails development environment on AWS Cloud9

Introduction

Suddenly I decided to start studying Ruby on Rails and decided to build an environment. Since it's a big deal, I'm going to build an environment with AWS Cloud9.

things to do

In this article, we will:

--AWS Cloud9 environment construction --Ruby environment construction --Installing and switching ruby version 2.5.1 using rvm --Rails environment construction --Installing rails version 5.2.1 using gem

AWS Cloud9 environment construction

Cloud9 is a service that allows you to use an IDE (Integrated Development Environment) in a cloud environment.

Since it runs on a browser, you can prepare a development environment with the same procedure even on PCs with different OSs and other environments. Features-AWS Cloud9 | AWS

Cloud9 environment creation

Transit to the Cloud9 screen from the AWS Management Console.

Click Create enviroiment </ b>. 20201011023747.png

Environmental setting

We will set up the Cloud9 environment to be created.

Give Name </ b> the name of your Cloud9 environment. It seems that you can decide freely, but this time I will use ruby-cloud9-env </ b>.

Click Next step </ b> when you are done.

20201011023821.png

Set the EC2 instance (virtual machine) </ b> used for the Cloud9 environment. All are fine by default.

Click Next step </ b>.

20201011023907.png

Check settings

You can check the settings of the environment to be built. After confirming, click Create enviroiment </ b>.

20201011023920.png

Transit to the Cloud9 IDE screen. After a short wait, you will be able to operate it.

This completes the construction of the Cloud9 environment.

20201011024006.png

Next, change the settings suitable for development in Cloud9.

Space visualization

Visualize the space symbol.

Click the ⚙ gear mark </ b> at the bottom right of the text editor. The settings will be displayed. Click Show Invisibles </ b>.

20201011024747.png

Ruby environment construction

From here, we will build the Ruby environment.

The terminal is displayed at the bottom of the Cloud9 screen. We will execute the command here.

20201011042946.png

First, update the library pre-installed in the OS. Basically, I don't think there will be any updates.

sudo yum update

20201011025015.png

Switch ruby version using rvm

This time, I would like to manage multiple versions of Ruby using RVM (Ruby Version Manager).

rvm installation

Clooud 9 comes with rvm pre-installed. Make sure rvm is installed just in case.

rvm -v

20201011025047.png

ruby-2.5.1 installation

Check the version of Ruby that can be switched with rvm at this stage.

rvm list

20201011025113.png

It seems that ruby-2.6.3 </ b> can be used. This time I want to use ruby-2.5.1 </ b>, so install it using rvm.

rvm install 2.5.1

20201011025150.png

Check the version of Ruby that you can switch to again when the installation is complete.

rvm list

20201011025207.png

ruby-2.5.1 </ b> has been added and you can see that it is current.

Just in case, check it with the Ruby command.

ruby -v

20201011025228.png

rvm default version change

You have now switched versions of Ruby using RVM. However, with the current settings, the ruby version will revert to 2.6.3 </ b> when the terminal is restarted.

Therefore, change the default version in RVM to 2.5.1 </ b>.

rvm --default use 2.5.1

20201011025304.png

Check the version of Ruby that can be switched.

rvm list

20201011025334.png

You can see that ruby-2.5.1 </ b> is current && default.

This completes the ruby environment construction.

Rails environment construction

From here, we will build the Rails environment.

rails installation confirmation

First, make sure that the rails command is installed.

rails -v

20201011025407.png

You can see that it is not installed.

gem installation

Rails is installed using the command gem </ b>. A gem is a package of Ruby applications and libraries.

Make sure gem is installed. You can use it if ruby is installed.

gem -v

20201011025430.png

You can confirm that it is installed.

rails installation

Now let's install rails using gem.

gem install rails -v 5.2.1 -N

You can use the -N option to skip the installation of various documents. (Installation will be faster)

20201011025538.png

Check the rails version when the installation is complete.

rails -v

20201011025601.png

I was able to confirm that it was installed.

That's all for building the Rails environment.

Finally

Building an environment for Ruby on Rails had a rather annoying image, but using Cloud9 (especially Windows) makes it easy to build an environment. I'm going to build some simple systems using Ruby on Rails.

Recommended Posts