(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.
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:
1 2 3 4 5 6 7
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:
- 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.
1 2 3 4 5 6 7 8 9 10
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:
1 2 3 4 5 6 7 8
Step 4. Your first Rails App
First you need to install Rails gem:
Create your new app:
Go to Gemfile and uncomment this line:
After that re-install gems:
And start it in your browser at http://localhost:3000
Step 5. Set Up Sublime Text as Code Editor
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.
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.
1 2 3 4
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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.
You need a Java Runtime installation before:
Download and install:
1 2 3
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:
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.
If you want a structured, instructor led program to level up to a professional level Ruby on Rails developer, check out our curriculum!