Setting up your environment can be difficult when you're first starting with Ruby. We want to get the following installed:
- Git
- Ruby 2.0
- A text editor
The setup instructions are broken down by the following platforms: Mac; Linux; and Windows.
Mac OS is the most popular platform for Ruby and Rails developers. To have a properly setup dev machine you want the following:
- Install free XCode app from the Apple store. Installing ruby on Mac OS requires the Command Line Tools that XCode gives you access to.
- Once XCode app is installed, go to Preferences > Downloads > Install Command Line Tools.
If you do not have OS X Mountain Lion, then you will need to do some more work to get the Command Line Tools installed.
- Create or Register an Apple ID. Register with the same Apple ID you use for other Apple services, such as iTunes, iCloud, and the Apple Online Store.
- Login to the Apple Developer Portal.
- Search for "Command Line Tools (OS X Lion) for Xcode"
- Download and install the package.
Homebrew is a package management system that makes it easy to install hundreds of open source projects and compile them from source for maximum performance on your machine.
$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press ENTER to continue or any other key to abort
Git is the version control system of choice in the Ruby community.
$ brew install git
==> Downloading http://git-core.googlecode.com/files/git-1.8.1.1.tar.gz
########################################################### 100.0%
RVM allows you to install and maintain multiple versions of Ruby.
More information about Ruby Version Mananger (RVM) can be found at http://rvm.io
$ \curl -L https://get.rvm.io | bash -s stable
$ source ~/.bash_profile
To list all of the possible ruby versions that you can install, use the command:
rvm list known
We recommend getting the latest stable version of Ruby, which is version 2.0.
NOTE: rvm install 2.0.0-p247 looks like the latest stable patch version at the moment. It might depend on brew install openssl
.
$ rvm install 2.0.0 --with-gcc=clang
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-2.0.0-p247.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: ~/.rvm/rubies/ruby-2.0.0-p247, this may take a while depending on your cpu(s)...
ruby-2.0.0-p247 - #downloading ruby-2.0.0-p247, this may take a while depending on your connection...
######################################################################## 100.0%
NOTE: If you run into an error like the following, you likely need to install sqlite first, as it is a common dependency:
Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config apple-gcc42 libyaml readline libxml2 libxslt libksba openssl sqlite',
please read ~/.rvm/log/ruby-2.0.0-p247/1368142352_package_install_autoconf_automake_libtool_pkg-config_apple-gcc42_libyaml_readline_libxml2_libxslt_libksba_openssl_sqlite.log
Solution:
brew install sqlite
Setting the default Ruby
$ rvm use 2.0.0 --default
If Mac OS isn't a possibility, then your next best bet is Linux. Among distributions, Ubuntu has the best support for Ruby and Rails development. You'll need:
- Git (
sudo apt-get install git-core
) - RVM (http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/)
You want to avoid managing Ruby, RubyGems, etc. through your package management solution (apt
). The packages available usually lag months behind the real source code repositories, and it is going to cause you massive headaches.
Instead, setup RVM and handle everything through there (as we'll discuss in the next section).
If you're going to be doing Rails work, then you should also install Node.js. You can get it from your distribution's package manager. If you're using Ubuntu, like above:
sudo apt-get install node
Getting started on the Windows platform is actually very easy. Engine Yard (http://engineyard.com) has put together the RailsInstaller (http://railsinstaller.org/), a single package installer with all the tools you need to get working. Make sure that, during the setup, you check the box to configure your environment variables. You can stop after step 2, once you've entered your email and name in the DOS prompt.
Beyond initial setup, though, there is going to be pain. As you add in more Gems and other dependencies you'll find that many of them utilize native extensions, code written in C for better performance. Unless the authors have put energy into being cross-platform, you'll run into issues.
If there is any way to avoid using Windows for your development environment, do it. For a free alternative, consider setting up a virtual machine with Virtual Box and Ubuntu Linux.
If you don't already have a favorite text editor, we recommend using Sublime Text 2.
iTerm2 is a replacement for Terminal that adds much customization & configurability.
Some features include: Split Panes, Hotkey Window, Search, Autocomplete, Mouseless Copy, Paste History, Instant Replay, Configurability, Full Screen, 256 Colors, Unixyness, Readability, Mouse Reporting, Growl Support, Exposé Tabs, Tagged Profiles, Multi-Lingual, and more.
A community-driven framework for managing your zsh configuration. Includes 120+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, macports, etc), over 120 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
NOTE: If you've already installed RVM, and are switching from BASH to Zshell (OMZSH), you'll need to copy the rvm loading scripts into ~/.zshenv
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
You can now customize your .zshrc file (See mine attached) If you'd like to have sublime be your default editor, please do the following:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/sub
Open a new terminal/iTerm shell
sub --help
Sublime help text should be output.
Ruby & Terminal Cheat Sheet