How to use Ruby on Rails on AWS Cloud 9

Mdiouf
6 min readJul 23, 2021

--

I have been studying rails more seriously for a couple of days now. In fact, I decided to become better at it with an objective to build apps and get a job in the field. So I started looking for the best books or videos to learn rails. I have found some interesting resources, like Udemy or Youtube. Yet the one I decided to go with is the Learn Enough Rails, by Michael Hartl.

Before reading the book, I thought the only way to use rails was to install it locally. After all, that’s how we do it with languages JavaScript (NodeJS). And probably for other ones.

But after trying to install rails on my M1 mac for about 3 days, without success. I decided to give up.

Rails, if you don’t know it, is hard to install. You have to follow a lot of steps to get it working on your machine. And if you are relatively new to the language like me, this sounds like mission impossible.

Online IDEs

Anyhow. I purchased the book and discovered a second option: using online IDE. And IDE or Integrated Development Environment is an interface that makes coding better. Think VS Code or Atom. You would use them on your local machine to write code. I love using both of them on my local machine but as said, installing rails on my M1 mac was a mess.

So as I learned in Michael Hartl’s book that it’s possible to use rails, without installing it. And that was awesome.

Using Rails online with Amazon Cloud 9

If you are having trouble installing Rails on your machine and don’t want to lose time, you have AWS Cloud 9. Since I started using it, everything is working smoothly. I can install my rails 6 apps without a problem. And the best part is…it’s free. Here’s what it looks like:

In what’s next, we will see how you can use AWS Cloud9 to get started with Rails. Some features of using cloud 9 include:

  • A user-friendly interface: you feel like you are in your local IDE
  • Compatible with a browser. You can use it on any laptop, without needing to install rails over again. As long as you have an internet connexion.
  • Picking from where you left off. I sometimes close my Chrome tabs in bulk. But I don’t have to worry because it saves everything (even the terminal instructions!).
  • No need to worry about colliding ports. I can work on 3 or 4 apps a day both running on port 3000 (the default port). This can bring a lot of hassle, especially if you close your local IDE without shutting down the running server. With a cloud IDE like Cloud 9, you don’t have to.
  • And finally, it’s so smooth, I can’t stress this enough.

How to get started with AWS Cloud 9

Here’s my experience from using AWS cloud 9 to build my first rails apps on an online IDE.

Although it’s free, you need to provide your credit card details while signing up. I have done it and didn’t get charged. So no need to worry about it. Now here’s step by step how you can set up your development environment using Amazon Cloud 9.

First, you need to create an AWS account

Getting started with AWS Cloud 9 is easy. Head over to the website and create your account.

Once you get that part ready, you can log into your account through this page.

Once you log in to your AWS dashboard, you can click on the “Services” link on the top left side and search for “Cloud9”. You’ll be directed to a page where you can create a new environment.

This will prompt a new page where you can provide a name and description for your new environment like this:

Click on the “Create environment” button. This will get you to a new page like this:

The description is optional even if you can put more details about your environment. Especially if you plan to have many ones. You can go to the next step.

In this step, you need to make one change. Select the Ubuntu Server platform instead of the default Amazon Linux tier.

You should now be set up, here’s what you should have at the end (by the time I’m writing this article).

After that, your environment should be ready. You can install the new version of rails. Let’s see how it’s done.

Checking your current ruby and rails version

What’s cool about this environment is it’s already set up with rvm (ruby version manager) and rails. The interface has a terminal where you can check it out like this:

In this example, I have ruby 2.3.0 install along with rails version 5.0.0. With rvm, you can choose which rails or ruby version to use. You can upgrade your current rails version by running the command:

gem install rails

Creating your first rails application

At this point, you can create your first rails application by running the command on the terminal:

rails new learnrails

The command rails new is followed by the name of your application. It can be any name you choose.

After the installation, you should see a new folder in your environment. This is your new rails application.

Extra step: installing yarn and webpacker

Creating your first rails application, the next thing is to install yarn and webpacker. To do that you should get into your rails directory first

cd learnrailscurl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.listrails webpacker:install

This will install webpacker on your rails app using yarn. The next step is to run your application now. Let’s see how it goes.

Running your rails app

The final step of this tutorial is to run your rails application. For that, you have the command:

rails server

What this command does it boot up a server for your rails app to run on. You can visit your app by clicking on the preview button at the top part of your app:

You can click on the button to pop out the app in a new window (3). At this point, you should get an error about the host being blocked. Fortunately, you have the solution right before your eyes:

We simply add the host to our config/environments/development.rb file like this:

At this point, you should restart your server (ctrl+c, then rails server again). You have your new rails app ready to go

--

--

Mdiouf

I am a full-stack developer with a passion for technology and learning new things. Founder of JavaScriptLearned.