Justin's Notes

A place to share what I have learned

Chruby

Background

I have been using RVM for installing and managing ruby. Recently, I have been hearing about chruby and how it would make my terminal run a bit fast because it is a little less invasive than RVM. I also like the simplicity of it all.

0. Before You Start

Remove current ruby version manager. If you have RVM like I did, then run:

rvm implode

1. Ruby-Install

Chruby dosen’t handle installing ruby but ruby-install does:

  • install ruby-install
brew install ruby-install
  • install any version of ruby
ruby-install ruby 2.1.2 # or whatever version you need

2. Setup chruby

  • Install chruby
brew install chruby
  • Config terminal by putting the below lines into your .profile or .bashrc file
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

3. Set default version of ruby

echo "ruby-2.1.2" > ~/.ruby-version

How Do I Create a Ruby Gem?

Background

Last week, I pulled a file out of my lib directory of a project because I thought that we might try and use it in another project. I really want to prevent a copy paste situation. So this led me to think about, how did I do this 8 months ago?

0. Before You Start

  • Create a RubyGems.org account
  • Make sure to query the name of your gem, to see if it already exists

1. gem install bundler Mou icon

Bundler will do most of the heavy lifting. Pick a name for your gem and run…

bundle gem my_gem

Now you should have a directory with your gem name and it contains all of the necessary file needed to start your gem.

2. Build Time

If you run ‘rake -T’ in the terminal, you will see…

rake build    # Build my_gem-0.0.1.gem into the pkg directory
rake install  # Build and install my_gem-0.0.1.gem into system gems
rake release  # Create tag v0.0.1 and build and push my_gem-0.0.1.gem to Rubygems

Run these commands:

  • rake build #to build your gem
  • rake install #just to make sure your gem installs without issue

3. Release my_gem

When the gem is ready for release to RubyGems.org

rake release

The first time you do this, you will be asked for your RubyGems.org credentials.

Done