If you have not created an AWS Cloud9 workspace already please go to this link:
How to create an AWS Cloud9 workspace.
Step 6: Open the Cloud9 Service
After we’ve signed in again, we’ll want to open up the Cloud9 Service.
At this point, you may encounter a message saying that your account is still being prepared.
In my case, I checked my email and read everything that came from AWS, taking any actions that were suggested. . This error was gone when I came back about an hour later, but your mileage may vary.
When we’re all set, visiting the Cloud9 service from the AWS Management Console should show you a page that looks like this:
Step 7: Create a new Cloud9 workspace
We’ll want to click the Create environment link. And then give our new workspace a name.
After moving to the next step, we’ll tell AWS what size workspace we want. The default settings work within the free tier and they should be fine.
Click through to the next step and then click the Orange Create environment button to start up your first workspace.
In a minute or so, you should have your first Workspace up and running:
Step 8: Change to the Dark theme (optional)
I prefer Cloud9’s classic dark theme, so I’ll show you how we can set that up now. Feel free to skip this step if you prefer the default flat theme.
To switch to the dark theme, we’ll want to select preferences from the AWS Cloud9 menu and find the themes tab.
Then we can select the classic dark theme.
Step 9: Install a backup version of Ruby
Now that we’ve got our first workspace created and looking good, we need to update yum so we have the latest software.
sudo yum -y update
When the command completes, we should see something like this:
Step 10: Remove the root rvm installation.
If we run
ruby -v in the terminal, we should see 2.4.1.
When we set up our instance, ruby 2.4.1 is already installed using a root installation of rvm. In order for bundler to work properly, however, we need to reinstall rvm in our home directory. Doing this will allow our account to have ownership over the rvm installations, which is necessary to allow bundler to install any missing dependencies for us.
After we’ve installed a fallback version of ruby (with the sudo yum -y update command), we can remove the root rvm installation using the following command:
sudo rm -rf /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm
Once this is done, we’ll restart our shell using this command
If we run
ruby -v again, we should see 2.0.0.
Step 11: Update our Bash Profile
We’ll need to configure our shell to handle our new installation of RVM upon initialization. So, we’ll use the curl command to copy a bash profile from github that handles this configuration. The bash profile is a file that contains bash commands that are loaded immediately before opening a new terminal window. They are useful for adding aliases (shortcuts for longer bash commands), and adding to environment variables you can use within your terminal session.
This file gives you some useful aliases for running git commands and starting a rails server and opening shotgun. (You can run your rails server by typing
rs into your terminal and visiting the preview URL for your workspace). The file also includes an alias for opening up the bash_profile from the terminal for editing in the nano text editor. You can open up the bash profile in nano by typing the
bp command (alias for
nano ~/.bash_profile). To copy this file into your own bash profile, run the following command:
The file should copy very quickly. After it is complete, run the
killall tmux command to restart your terminal session (this will load the bash profile into your shell). To test that it’s working, you can run
bp in your session and you should see the bash_profile in the nano text editor. (press ctrl + X to exit and return to your shell session).
Step 12: Reinstall RVM
Next, we’ll install rvm in our home directory. To do this, we’ll need to get the gpg keys first:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Next, we can run the installation of RVM:
curl -sSL https://get.rvm.io | bash -s -- --path ~/.rvm --auto-dotfiles
After the installation runs, we’ll probably get a warning that we need to unset GEM_HOME (an artifact from our previous rvm installation). So, let’s do that:
Next, let’s restart the session using:
and we can check that rvm is installed properly by running:
We should see that no rubies are installed currently.
Step 13: Install Ruby 2.3.3
Now that RVM is installed, let’s install Ruby v.2.3.3. The installation will take a few minutes to run.
`rvm install 2.3.3
rvm use --default 2.3.3
ruby -v `
# should return 2.3.3
When it’s finished we should see something like this:
Step 14: Install some gems
First, we’ll grab updates from rubygems.
gem update --system
Next, we’ll install bundler, nokogiri and rails.
`gem install bundler
gem install nokogiri
gem install rails`
These will take a while to run as well. When they’re done you should see something like this:
Step 15: Install PhantomJS
npm install -g phantomjs-prebuilt
This one shouldn’t take too long to run and looks like this when it’s complete:
Step 16: Install the Learn Gem
There are a couple of things we need to do to get the learn gem working in Cloud9. First, we’ll want to install it using the following command:
gem install learn-co
This will install 36 gems. Next, we’ll want to authenticate the gem with our learn account. We can trigger this by running the
learn hello command. We’ll see the following message:
Connecting to Learn...
To connect with the Learn web application, you will need to configure
the Learn gem with an OAuth token. You can find yours at the bottom of your profile
page at: https://learn.co/your-github-username.
Once you have it, please come back here and paste it in:
This next bit you’ll do on your own. After you visit your profile on learn.co, scroll to the bottom and you’ll find the token there. Copy the token and paste it in here and the gem should be authenticated with our account. If you type in
learn hello again, the gem should greet you by name.
Step 17: Set up SSH keys for GitHub
First, we’ll need to generate a pair of SSH keys for use with github (one private and one public). We can generate the keys with the following command, replacing firstname.lastname@example.org with the email we use for our github account.
ssh-keygen -t rsa -b 4096 -C "email@example.com”
We will be presented with three prompts. Simply hit enter each time to accept defaults. After we’ve generated the key, we’ll want to copy it so we can add it to our GitHub account. Use this command to copy the public key into a file called key.txt:
cat ~/.ssh/id_rsa.pub > key.txt
Open key.txt and copy its contents to your clipboard. Once we’ve got the key copied, let’s open up GitHub in our browser, make sure we’re logged in, and click on the settings option underneath the profile menu.
Next, we’ll want to find the SSH keys option on the left hand menu.
Once we’re there let’s click the New SSH button, give our key a name, AWS Cloud9, and paste the key into the textarea field. When we’ve added the key to our account, it should look something like this:
After adding the key to our account, we can test that it was successful by running
ssh -T firstname.lastname@example.org
from our Cloud9 IDE terminal. We should see:
Hi our_github_username! You've successfully authenticated, but GitHub does not provide shell access.
Step 18: Configure Our directory structure.
We can use the learn directory command to set the directory that the learn open command will clone our lessons to. I like to set up my directory structure to mirror the sections and subsections of the curriculum. For instance, if I’m working on a lab in the CRUD with Rails subsection of the Rails section, I’d want to clone lessons into rails/crud-with-rails. To set that up, we’ll want to create those folders first.
Now that they’re created, let’s cd into that subdirectory and print out the full path:
Let’s copy the output of that
pwd command and then run the
learn directory command and paste in that path to tell learn to clone lessons into that directory:
To test this out, we can try cloning the form_for lab using the learn open command. First, find the GitHub icon just to the right of the Open IDE button and click on it.
Then, once we’re on the page for the GitHub repo, we’ll want to right click on the repo name to copy it to your clipboard.
Once we’ve got that copied, come back to the Cloud9 terminal and type in
learn open <paste in rails-form_for-lab-v-000>. When we hit enter, we’ll find the lab is cloned into our workspace within the desired folder.
When you open future labs, you’ll normally only need to run the
learn open command in the terminal and that will handle getting your current lab for you. If you want to open one that’s farther ahead in the curriculum, you’ll need to repeat the process above, finding the repo and copying the name to paste as an argument to the learn open command.
Step 19: Add Color to Test Output
By default, our rspec test output will come in all white when we run the
learn command. To add the color and additional details, let’s run the following command to create a .rspec file to handle default options:
echo “--color --format=documentation” > ~/.rspec
Step 20: Run your code in the browser.
In Sinatra, we’ll be able to run our code by running
shotgun in the terminal. After the server is running, we’ll want to find the preview button at the top of the Cloud9 window and select Preview running application.
After you select the option, your terminal will split and you’ll see a preview appear.
In the top right of the preview window, there’s a link to pop out the preview into another browser tab. You’ll want to click on that so you can see the page properly.
Once we’ve done this, I recommend bookmarking this page in Chrome. Whenever we run shotgun (or rs to run the rails server later on), our code will be running at this URL.
Running our rails server, we’ll want to use the alias provided in the bash profile we downloaded earlier. To start up the server, you’ll run the
command and visit this same URL in the browser to see your app running in the browser.