Getting Started With Ruby on OSX
I recently needed to some work in Ruby. I’m a life-long Python dev and I took some notes for anyone else in my position that is starting off and not know what tools to use:
Use RVM To Manage Ruby Distributions
RVM is Ruby’s version of Python’s virtualenv. To install it, you can execute the following commands:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable --ruby
After it is installed, execute the following commands:
rvm reload
echo rvm_auto_reload_flag=1 >> ~/.rvmrc
Install Specific Version Of Ruby
If you want to see which version of Ruby rvm
installed by default, simply execute
If you are working on an existing Rails app, the GemSpec
file will specify a specifc version of Ruby:
Your Ruby version is 2.2.0, but your Gemfile specified 2.1.5
This is no problem, just install that specific version of ruby using rvm
as follows:
Install Third Party Libraries
If you are used to Python, you are used to executing
pip install -r requirements.txt
The analogous command in Ruby is:
bundle install
Running Unit Tests
If you want to run all the unit tests in a Rails project, then you can easily do that with the following command
bundle exec foreman run rspec
Switching Between Multiple Versions of Ruby
If you need to switch between multiple Ruby installations using rvm
, you can do it with the following command
rvm use 2.1.1