Ruby On Rails For Mac



For

(Related article: How to Install Ruby on Rails for Mac OSX Mavericks)

For this post we are based on a clean “Ubuntu 14.04 LTS” installation, nevertheless I have installed these tools in previous versions with the same steps. And similar steps should work in other Linux ditros.

The easiest way to use Postgresql on Mac is to download and install the With Postgresql running, add gem 'pg' to the Gemfile in your rails project and run bundle install to install the Postgresql Ruby driver.

  • $ ruby -version ruby 2.0.0p481 (2014-05-08 revision 45883) universal.x8664-darwin14 In this example, the version of Ruby is 2.0.0, and the number following the letter p is the current patch or build number. Newer versions of Ruby are available, and the Mac’s version will change if you install updates.
  • Ruby on Rails is a great language, and framework, for creating highly interactive websites. Discover how to set up Rails, and program in Ruby on your Apple Mac.
  • This will take about 30 minutes. We will be setting up a Ruby on Rails development environment on Mac OS X 10.10 Yosemite. Older versions of OS X are mostly compatible so follow along as far as you can and then Google search for any problems you run into.

For day to day Ruby on Rails development work we need several tools to be porperly installed and running:

  • Git: Right now this is the standard Version Control System in the industry. Even more!! I work with git in all my client projects since a few years ago.
  • Rbenv (and ruby): lightweight Ruby Version Manager to isolate Ruby versions and project dependencies.
  • Rails: Our favourite framework to build Web apps.
  • Sublime Text Editor: lightweight modern editor.
  • PostgreSQL: Probably the best Database in the open source market (in fact my favourite)

For Ubuntu my first recommendation, before to make a big installation, is updating system packages:

Step 1. Installing Git

Git is the standard VCS for the Ruby community, and probably for the IT industry at this moment. Also it is pretty simple to install at Ubuntu:

Git will need your email and name at least to identify your commits, but I have added some other configurations interesting for my day-to-day work. Execute each line in prompt:

Probably you will use Github to deliver code to your clients, and it will need to identify you through your ssh-keys. You can follow this guide in order to create ssh keys (if you do not have them yet) and configure your account.

This process is similar with other Git providers like Bitbucket or your Company owned Git servers.

Step 2. Dynamic prompt with Git and ANSI colors

Tobias Sjösten wrote a pretty useful article explaining this.

This hack will:

  • Put our current branch in prompt
  • Change color if there are files to commit

This gives you a quick status of your changes in project in a quick eye-shot. You just have to add the following code to ~/.bash_profile file:

You should restart terminal for these changes to take effect.

Step 3. Install Ruby with RBENV

RVM and RBENV are the most used Ruby Version Managers among developers. Rbenv is lighter and solves the dependency isolation problem working with Bundle (the default dependency management gem for Rails).

RBENV give us several advantages:

Ruby On Rails For MacRuby on rails for mac
  • The obvious ‘apt-get install ruby’ is outdated, and you probably want to work with latest ruby versions.
  • Allow different versions of ruby in the same machine, which will be useful when we write code in different projects.
  • Dependency isolation working with bundle.

You need Git that was installed previously to install RBENV.

With commands above you have installed Rbenv and the ruby versions builder, and give access to them directly from command prompt. Please, restart your terminal to load Rbenv.

The only disadvantage of BINSTUBS is that you have to remember to run the following command

Now, you can install every ruby version with a command:

Step 4. Your first Rails App

First you need to install Rails gem:

Create your new app:

Ruby On Rails Virtual Machine

Go to Gemfile and uncomment this line:

The gem “Therubyracer” is Google V8 engine wrapped in a gem, in order to have the capability of evaluating JavaScript code from Ruby. Pretty interesting in Rails templates and assets.

After that re-install gems:

And start it in your browser at http://localhost:3000

Step 5. Set Up Sublime Text as Code Editor

Windows

There are several code editors in the market to edit ruby code: SublimeText, RubyMine, Aptanta,…. Or Opensource like vim, gedit or emacs. Sublime Text is an excellent choice if you want a lightweight editor with great features and a modern user interface.

Ruby On Rails State Machine

Download and unzip last version from the web page. In order to give access from command prompt:

Now you can open your Rails app by typing:

The convention for Ruby programs is to use two spaces as indentation. You can follow Sublime Text 2 => Preferences => Settings - User and add these lines.

Step 6. PostgreSQL installation

This is a pretty good Database and maybe this will be your Production relational database. So worth it to take a look at how to integrate it with rails:

You can add the gem to your Gemfile:

And run bundle again: bundle install, to make PG gem installation.

After that your Database config file should be like:

Extra Ball. Set up RubyMine

Here at Tealeaf Academy we recommend Sublime for our students, because is lighter and easy to use. But if you need a more complete editor: with debugger, Git or Ticketing System integration, plugins … . RubyMine is a great choice.

Ruby On Rails For Mac High Sierra

You need a Java Runtime installation before:

Download and install:

They allow you a 30 day trial version, after that you should purchase a license.

Then you can open every Rails application within the project folder with the command:

Ruby on rails for mac osx

Conclusion

Well, this is just the beginning. Here we just installed our Dev environment with a bunch of really useful tools, which you will use in your day-to-day work.

Install Ruby Mac

If you want a structured, instructor led program to level up to a professional level Ruby on Rails developer, check out our curriculum!