Setting up your environment can be difficult when you're first starting with Ruby. We want to get the following installed:
- Git
- Ruby 2.2
- A text editor
The setup instructions are broken down by the following platforms: Mac
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.
- In terminal type
xcode-select --install
- Click install if a window pops up.
If you don't already have a favorite text editor, we recommend using Sublime Text 3.
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 http://install.ohmyz.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*
If you'd like to have sublime be your default editor, please do the following:
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sub
Open a new terminal/iTerm shell
sub --help
Sublime help text should be output.
After that you can edit your .zshrc file to change your zshell settings.
sub ~/.zshrc
Here are some useful settings to add.change in your .zshrc file.
ZSH=$HOME/.oh-my-zsh
ZSH_THEME="muse"
DISABLE_AUTO_UPDATE="true"
DISABLE_LS_COLORS="false`"
plugins=(bundler git osx sublime brew gem rvm ruby rails web-search)
export EDITOR="sub --wait"
source $ZSH/oh-my-zsh.sh
# autocorrect is more annoying than helpful
unsetopt correct_all
You can find out more about the plugin's here: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
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 -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> 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
brew install git
brew install sqlite
brew install openssl
brew install postgresql
brew install gcc
brew install imagemagick
brew install node
brew install redis
brew install watch
brew install wget
# follow postgresql setup
postgres -d /usr/local/var/postgres
$ initdb /usr/local/var/postgres -E utf8
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.
Ruby & Terminal Cheat Sheet
http://pragtob.github.io/rails-beginner-cheatsheet/
Sublime Shortcuts Cheat Sheet