Aston J

Ruby dev environment (Yosemite)

Posted on: May 12th, 2015 by AstonJ 10 Comments

Having recently reformatted my Mac, I thought I’d jot some notes down on setting up a Ruby dev environment too.

In this post we’ll set up our fresh dev enviroment for Ruby, and cover installing and setting up the following…

  • Xcode/GCC
  • Command line tools
  • Homebrew
  • Chruby
  • Ruby
  • Rubygems
  • Rails
  • Postgres
  • MacVim

Xcode or GCC

Simply download and install Xcode from the App store, OR, get GCC from here.

Command Line Tools

Once Xcode has installed, open it, then go to preferences > downloads, and install command line tools. Or alternatively, enter this in terminal:

xcode-select --install

Homebrew

In the terminal copy and paste the following:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Chruby, Rubygems, Rails, Git, ImageMagick

Chruby is the new Ruby version manager that most Ruby devs seem to be using and recommending nowadays. I recently tried it and like it too! (Note, not to be installed if you have or intend to use RVM or Rbenv.)

Chruby

brew update
brew install chruby
brew install ruby-install
ruby-install ruby 2.2.2

In ‘~/.bash_profile’ add the following lines:

# Chruby
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-2.2.2

Which makes Ruby 2.2.2 the default Ruby. Then simply add a .ruby-version file with the Ruby version you would like (e.g ‘2.2.2’) for that directory and all directories inside it unless they specify their own .ruby-version. Easy huh!?

You’re rubies are now either in /opt/rubies or ~/.rubies.

Update RubyGems and install Rails

gem update --system

Now for Rails:

sudo gem install rails

Restart terminal and check your versions by:

ruby -v
rails -v

Update Homebrew and let’s get brewing!

Let’s update Homebrew and install some software to get you going; ImageMagic, Git and Postgres.

brew update
brew install ImageMagick
brew install git
brew install postgres

Then to start Postgres and on startup, run the lines it tells you to, mine were:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Then create your initial db:

createdb

Then:

psql
CREATE ROLE postgres LOGIN CREATEDB;

to create your posters user and check it works ok (use CTRL Z to come out).

Code Editors

Finally you need a decent editor! Personally I use MacVim and sometimes TextMate 2.

Get TextMate 2 from here.

To install MacVim:

Get the latest snapshot from here and double click then move to your applications folder (or you can do ‘brew install macvim’).

Once installed, you’ll want to drag the ‘mvim’ file to your desktop, and then in terminal:

mv ~/Desktop/mvim /usr/local/bin

This allows you to use ‘mvim’ in the terminal.

Next you’ll want to use Janus, which can be installed by running this in terminal:

curl -Lo- https://bit.ly/janus-bootstrap | bash

That’s it! Tho, if you want to learn more about Vim, Janus or install a nice theme, check out this post

Tags: , , , , , , , ,
  • Pim Snel
    • http://astonj.com AstonJ

      Hey Pim, I’ve heard a lot of good things about OMZ but haven’t tried it yet – does it have split screen mode like iTerm? (That’s the main reason why I use iTerm.)

  • https://www.alchemists.io Brooke Kuhlmann

    If it helps, I’ve automated a lot of this via Bash through my [OSX](https://github.com/bkuhlmann/osx) project. Opinionated for my preferences but customizable for yours. Might be of interest.

    • http://astonj.com AstonJ

      That looks pretty neat Brooke! It’s also interesting to see your toolset – perhaps you could do a blog post on your favourites :-)

  • Alif Khandoker

    after follow your tutorial about Chruby i face now this problem need your help

    rails -v

    Ignoring atomic-1.1.99 because its extensions are not built. Try: gem pristine atomic –version 1.1.99

    Ignoring atomic-1.1.16 because its extensions are not built. Try: gem pristine atomic –version 1.1.16

    Ignoring atomic-1.1.10 because its extensions are not built. Try: gem pristine atomic –version 1.1.10

    Ignoring bcrypt-3.1.10 because its extensions are not built. Try: gem pristine bcrypt –version 3.1.10

    Ignoring bcrypt-3.1.9 because its extensions are not built. Try: gem pristine bcrypt –version 3.1.9

    Ignoring bcrypt-3.1.7 because its extensions are not built. Try: gem pristine bcrypt –version 3.1.7

    Ignoring bcrypt-ruby-3.0.1 because its extensions are not built. Try: gem pristine bcrypt-ruby –version 3.0.1

    Ignoring bigdecimal-1.2.7 because its extensions are not built. Try: gem pristine bigdecimal –version 1.2.7

    Ignoring binding_of_caller-0.7.3.pre1 because its extensions are not built. Try: gem pristine binding_of_caller –version 0.7.3.pre1

    Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem pristine binding_of_caller –version 0.7.2

    Ignoring byebug-5.0.0 because its extensions are not built. Try: gem pristine byebug –version 5.0.0

    Ignoring byebug-4.0.5 because its extensions are not built. Try: gem pristine byebug –version 4.0.5

    Ignoring byebug-4.0.3 because its extensions are not built. Try: gem pristine byebug –version 4.0.3

    Ignoring byebug-4.0.2 because its extensions are not built. Try: gem pristine byebug –version 4.0.2

    Ignoring byebug-3.5.1 because its extensions are not built. Try: gem pristine byebug –version 3.5.1

    Ignoring byebug-3.4.0 because its extensions are not built. Try: gem pristine byebug –version 3.4.0

    Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector –version 0.0.2

    Ignoring eventmachine-1.0.7 because its extensions are not built. Try: gem pristine eventmachine –version 1.0.7

    Ignoring executable-hooks-1.3.2 because its extensions are not built. Try: gem pristine executable-hooks –version 1.3.2

    Ignoring ffi-1.9.8 because its extensions are not built. Try: gem pristine ffi –version 1.9.8

    Ignoring ffi-1.9.6 because its extensions are not built. Try: gem pristine ffi –version 1.9.6

    Ignoring gem-wrappers-1.2.7 because its extensions are not built. Try: gem pristine gem-wrappers –version 1.2.7

    Ignoring hiredis-0.4.5 because its extensions are not built. Try: gem pristine hiredis –version 0.4.5

    Ignoring hitimes-1.2.2 because its extensions are not built. Try: gem pristine hitimes –version 1.2.2

    Ignoring json-1.8.3 because its extensions are not built. Try: gem pristine json –version 1.8.3

    Ignoring json-1.8.2 because its extensions are not built. Try: gem pristine json –version 1.8.2

    Ignoring kgio-2.9.3 because its extensions are not built. Try: gem pristine kgio –version 2.9.3

    Ignoring kgio-2.9.2 because its extensions are not built. Try: gem pristine kgio –version 2.9.2

    Ignoring mysql2-0.3.18 because its extensions are not built. Try: gem pristine mysql2 –version 0.3.18

    Ignoring mysql2-0.3.16 because its extensions are not built. Try: gem pristine mysql2 –version 0.3.16

    Ignoring nokogiri-1.6.6.2 because its extensions are not built. Try: gem pristine nokogiri –version 1.6.6.2

    Ignoring nokogiri-1.5.11 because its extensions are not built. Try: gem pristine nokogiri –version 1.5.11

    Ignoring pg-0.18.1 because its extensions are not built. Try: gem pristine pg –version 0.18.1

    Ignoring pg-0.17.1 because its extensions are not built. Try: gem pristine pg –version 0.17.1

    Ignoring psych-2.0.13 because its extensions are not built. Try: gem pristine psych –version 2.0.13

    Ignoring raindrops-0.13.0 because its extensions are not built. Try: gem pristine raindrops –version 0.13.0

    Ignoring redcarpet-3.2.3 because its extensions are not built. Try: gem pristine redcarpet –version 3.2.3

    Ignoring redcarpet-3.2.2 because its extensions are not built. Try: gem pristine redcarpet –version 3.2.2

    Ignoring rinku-1.7.3 because its extensions are not built. Try: gem pristine rinku –version 1.7.3

    Ignoring rinku-1.5.1 because its extensions are not built. Try: gem pristine rinku –version 1.5.1

    Ignoring sqlite3-1.3.10 because its extensions are not built. Try: gem pristine sqlite3 –version 1.3.10

    Ignoring sqlite3-1.3.9 because its extensions are not built. Try: gem pristine sqlite3 –version 1.3.9

    Ignoring therubyracer-0.12.2 because its extensions are not built. Try: gem pristine therubyracer –version 0.12.2

    Ignoring therubyracer-0.12.1 because its extensions are not built. Try: gem pristine therubyracer –version 0.12.1

    Ignoring thin-1.6.3 because its extensions are not built. Try: gem pristine thin –version 1.6.3

    Ignoring unicorn-4.8.3 because its extensions are not built. Try: gem pristine unicorn –version 4.8.3

    Rails 4.2.1

  • Alif Khandoker

    my ~/.bash_profile

    source ~/.profile

    #PS1=”u$w$ ”

    export PATH=”/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH”

    #export CC=/usr/local/bin/gcc-4.9

    #export CPP=/usr/local/bin/cpp-4.9

    #export CXX=/usr/local/bin/g++-4.9

    [[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm” # Load RVM into a shell session *as a function*

    export CLICOLOR=1

    export LSCOLORS=GxFxCxDxBxegedabagaced

    export PS1='[e[0;32m][u@ W]$[e[0m] ‘

    # Chruby

    source /usr/local/share/chruby/chruby.sh

    source /usr/local/share/chruby/auto.sh

    chruby ruby-2.2.2

    • http://astonj.com AstonJ

      Looks like you didn’t remove RVM – you can’t run more than one Ruby version manager at the same time. Post a thread on MetaRuby.com if you are still stuck and one of us will try to help you.

      • Alif Khandoker

        how to remove this now sir ?

        • Alif Khandoker

          now its work thanks

  • Alif Khandoker

    is anybody can help he whats going please i don’t understand thanks advance

    [alif@ sample_app1]$ sudo gem install rails

    Password:

    Successfully installed rails-4.2.3

    Parsing documentation for rails-4.2.3

    Done installing documentation for rails after 0 seconds

    1 gem installed

    [alif@ sample_app1]$ rails -v

    Rails 4.2.1

    i install already rails-4.2.3 but when i run rails -v its showing 4.2.1 :(