Tuesday, May 15, 2012

How to install Rvm, Ruby, and Rails in Ubuntu 12.04

A concise guide to get Rails running locally.

1. Install package dependencies

sudo apt-get install zlib1g zlib1g-dev build-essential
sqlite3 libsqlite3-dev openssl libssl-dev curl git
libmagick++-dev libmagick++4

2. Install rvm from Github source

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

3. Reload terminal shell

source /home/ben/.rvm/scripts/rvm

4. Add rvm to bash

echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile

5. Add any additional requirements specified by rvm

rvm requirements
copy / paste any Additional Dependencies: specified in the terminal output into sudo apt-get

6. Install ruby version to rvm

rvm install 1.9.3-p194

*Update rvm and Ruby version (useful to know)
rvm get stable
rvm list known

Troubleshooting
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Open your Terminal  and select Edit > Preferences > Run command as login shell (make sure it is selected)

7. Setup default ruby version in rvm

rvm use 1.9.3-p194 --default

8. Install rails

gem install rails

9. Install RSpec

gem install rspec

10. Install Bundler

gem install bundler

If you see ERROR: Gem bundler is not installed, run `gem install bundler` first. when running bundle change https://rubygems.org to http://rubygems.org in your Gemfile.

Saturday, May 12, 2012

Sublime Text 2 Setup for Rails

NB: Please see this post for Sublime Text 2 installation

After installing Sublime Text 2 these are the settings I use and packages I install to assist with Ruby on Rails development. Use all or some of these to suit your own needs.

Remove the Minimap 

View > Hide Minimap

Install Package Manager

View > Show console

Copy code below / paste / enter


import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

 

Install Ruby / Rails related Packages 

Preferences > Package Control > Package Control:Install Package
  • ERB Insert and Toggle Commands 
  • Rails Related Files 
  • RubyTest 
  • Rspec 
  • Guard 
  • Haml 
  • Sass 
  • Coffeescript 

 

User Settings

Preferences > Settings - User

Copy code below / paste / save

{
"color_scheme": "Packages/Color Scheme - Default/railscasts.tmTheme",
"font_face": "Droid Sans Mono",
"font_size": 12,
"scroll_past_end": false,
"detect_indentation": false,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true
}

 

Create a plugin to Open file in browser

Tools > New plugin...

Copy code below / paste / save as OpenBrowser.py

# OpenBrowser.py
import sublime, sublime_plugin
import webbrowser

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      url = self.view.file_name()
      webbrowser.open_new(url)

 

Add Keybindings to Open file in new browser and to insert ERB

Tools > Command Palette > "User Key bindings"

Copy code below / paste / save

[
{ "keys": ["ctrl+shift+b"], "command": "open_browser" },
{ "keys": ["ctrl+shift+."], "command": "erb" }
]

 

Monday, May 7, 2012

Sublime Text 2 - Linux Textmate Alternative

There are plenty of editors and IDE's out there for Linux Rubyists and my search was based on an editor that was modern, fast, and a viable alternative to the popular Mac only editor Textmate.

Sublime Text 2 came out on top, as my editor of choice, for its features, speed, and ability to use Textmate themes. Its not perfect or free (price) yet... while its in beta status you are free to use it (with minor nagware). To get started see below or download directly (more detailed setup instructions in my next blog post).

Ubuntu install via the webupd8 maintained repo

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2-dev
or
sudo apt-get install sublime-text-2-beta

Install Railscasts theme


Copy
https://raw.github.com/ryanb/textmate-themes/master/railscasts.tmTheme

Place it here
.config/sublime-text-2/Packages/Color Scheme - Default

Select it
Preferences > Color Scheme > railscasts

Sunday, May 6, 2012

Rails + OSX Developer Monopoly

Why are so many Rails developers using the Apple Mac?

  • 37 Signals use them! They even made a cheezy video about it!! 
  • Build quality is good and its a fashionable tech accessory 
  • Single platform across a team of developers makes for an easier life and Mac is the obvious choice
  • Textmate, the modern standard Rails text editor in many ways, is Mac only software
I’m not trying to dissuade anyone from using a Mac for Rails development – like many Linux users I like having a choice.

Ruby on Rails is not, last time I checked anyway, a Mac specific programming language / web framework.

Having just moved to the latest Ubuntu (12.04 LTS) as a platform for my RoR projects i’m finding it a comparably slick alternative to the OS X monopoly.