Skip to content

Instantly share code, notes, and snippets.

@ankushagarwal
Last active August 29, 2015 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ankushagarwal/9411676 to your computer and use it in GitHub Desktop.
Save ankushagarwal/9411676 to your computer and use it in GitHub Desktop.
Rubies and Rvm

Managing rubies and rvm on OSX

Get rid of rvm

Unistall rvm ( if there exists one )

rm -rf ~/.rvm

Fresh install rvm

\curl -sSL https://get.rvm.io | bash -s stable

Bash/Zsh profile

  • Add .rvm/bin to your path
export PATH=$HOME/.rvm/bin:$PATH
  • Load rvm as a function
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
  • Make sure that the above two steps happen only once in your bash/zsh profile

Download rubies

  • rvm list known gives the list of known rubies
  • Install a particular ruby using rvm install <ruby-version>
  • Example :
rvm install ruby-2.1.1

Gems and Gemsets

  • Create gemsets for every fricking project.
  • Never install global gems
  • To create a gemset for version 2.1.1
rvm use ruby-2.1.1
rvm gemset create project_name
  • As simple as that

Using Gemsets

  • rvm gemset_name can be run to use a particular gemset
rvm ruby-2.1.1@gemset_name

Project ruby version and gemset management

  • Create a .ruby-version file in the root of the project. It should contain the ruby version being used for the project
echo "ruby-2.1.1" > .ruby-version
  • Create a .ruby-gemset file in the root of the project. This file should contain the name of the gemset used for this project. Typically it is the same as the project name.
echo "project_gemset" > .ruby-gemset

Alernative way of ruby-version and gemset management using .rvmrc

  • The following command can be run to create gemsets and the .rvmrc file for projects
rvm ruby-2.1.1@my_project --create --rvmrc
  • Note : This is not compatible with other ruby version managers. Use this only if you are planning to use rvmrc.

Bundler for managing project gems

  • Create a Gemfile in your project
source 'https://rubygems.org'
gem 'rails'
  • Use bundle to install the required gems
bundle install
  • This creates a Gemfile.lock which is a locked version of all gems and their versions and dependencies.

  • Execute a gem in the bundler's environment using bundle exec

bundle exec rspec spec/models

Other stuff

Set default ruby

rvm use --default 2.1.1

Update rvm

rvm get stable

References

@gregmolnar
Copy link

instead if .rvmrc I think it would be better to generate .ruby-version and .ruby-gemset to keep your projects compatible with other ruby version managers.

@ankushagarwal
Copy link
Author

Thanks @gregmolnar. Let me update this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment