in Code

Getting started: coding Ruby in the terminal

A New York UPS center/metaphor

I typed my first HTML in a Codecademy browser window before moving on to build HTML, CSS and PHP sites. Now, I’m enrolled in the Flatiron School boot camp, coding in an online learning environment again, and realized I’ve never actually coded Ruby (the first part of the curriculum) in the wild.

Here’s my quick take on setting up to code in the terminal on a Mac, in case anyone else’s Ruby journey thus far has been mostly online.

Install Rails, Homebrew, git, RVM, gems, SQLite and Node on Mac OS

I ended up using a Flatiron tutorial to install these programs, but tried the first thing I found online first. I ended up with lots of errors. So, I uninstalled and reinstalled, and things went a lot more smoothly the second time around.

I didn’t have the Learn IDE installed, and I didn’t set up the Learn gem because I’m still planning to finish my coursework online.

Adding a SHH key to GitHub

This is one of the steps in the above tutorial. For specific instructions from GitHub on using the SHH key, click here. I was afraid this would somehow disrupt Flatiron’s Learn.co/GitHub system, but it didn’t. I added my key to all the other keys.

Commands for coding in the terminal

You code in the terminal (Applications > Utilities > Terminal), where you just installed Rails and the other systems, using commands. As a Ruby newbie, I’m not ashamed to say that this simple, obvious fact was a revelation.

Here’s a basic tutorial by Railsbridge on using commands in the terminal.
Another tutorial by Thoughtco on using the command line.

Coding Ruby locally

Single file
I opened my text editor, Sublime, wrote some Ruby code and saved the file as my_program.rb to my desktop. I navigated to it in the terminal (by typing: cd desktop) and then ran it: ruby my_program.rb. The code ran in the terminal.

Running a program with multiple files
I wrote a sample Ruby CLI with multiple files, including a bin and a lib folder. To run it, I navigated to the program folder on the desktop, all the way to greet.rb in the bin folder (which requires the lib file):

cd desktop (enter)
cd greetings_earthing (enter)
cd bin (enter)
ruby greet.rb
=> Hello, earthling! What is your name?

Using GitHub from the terminal

I created a new repository on GitHub and set it to private (since I’m just practicing). Then, I actually selected upload files and dragged and dropped in my program from the desktop. So, not exactly interacting with GitHub form the terminal yet, but there will be opportunity.

Other ways to upload to GitHub
Cheat sheet of Git commands

If I missed anything in this simple guide, connect with me on Twitter and let me know! @SaraHarvy