path snippets

Find the installation directory of a RubyGem package programmatically

Tagged ruby, rubygems, gem, path, package  Languages ruby

This snippet prints the full path to the Rails installation directory--the path is retrieved using the RubyGems API:

require 'rubygems'
# Specify version number
puts'rails', '=1.0.0').first.full_gem_path

Example output:


To find the directory where your gems are hiding, use:

gem env

There's also the gem which command:

$ gem which activesupport
(checking gem activesupport-2.3.2 for activesupport)

SSH "bundle: command not found"

Tagged bashrc, bash_profile, ssh, path  Languages bash

Behold ~/.bashrc:

# If not running interactively, don't do anything 
[ -z "$PS1" ] && return

Don't put "export PATH" or anything else important below that line containing "return", put it above.

If you're using SSH to execute commands on the server the script will exit on that line, and with Rails bundler you'll then get errors like this:

bash: bundle: command not found

Still not working? Maybe you're running the command through SSH and bundle (or rbenv/rvm) is not in your PATH variable:

$ ssh sandbox 'echo $PATH'

Now try this:

$ ssh sandbox 'source ~/.bashrc && echo $PATH'

Next, figure out why the command is not in your path.

It could be because your .bashrc is missing this:

export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"

It could be something else…