How do I run a Ruby Gem?

19,787

Solution 1

It seems that Debian/Ubuntu drops ruby gems into /var/lib/gems/1.8/bin.

So the solution (at least for Ubuntu/Debian) is:

$ sudo -s
# echo 'PATH=/var/lib/gems/1.8/bin:$PATH' > /etc/profile.d/gemspath.sh
# chmod 0755 /etc/profile.d/gemspath.sh

...and then open a new shell session.

(This is fixed in Ubuntu 11.10.)

Solution 2

If you happen to have installed Ruby through rbenv, you'll need to execute the following command

rbenv rehash

Solution 3

On macOS I had to add the gem executable directory to the path.
Add these lines to your ~/.bashrc file, and reopen the terminal to refresh the env vars.

# gem                                                                      
gembin=`(gem env | sed -n "s/.*EXECUTABLE DIRECTORY: \(.*\)/\1/p")`
export PATH=$gembin:$PATH

Solution 4

If you use macOS and you:

  • I don't know/care about Ruby.
  • I just want to run this program.
  • Why is this so complicated?

Then run:

~/.gem/ruby/*/bin/jekyll

where jekyll is the thing you just installed with gem install.

Share:
19,787
Xkeeper
Author by

Xkeeper

I get mad about web design a lot, and I run a wiki dedicated to digging up unused/buried content in video games over at https://tcrf.net

Updated on June 06, 2022

Comments

  • Xkeeper
    Xkeeper almost 2 years

    This might seem stupid, but I recently tried to install SASS and followed their instructions:

    $ gem install sass 
    $ sass --watch [...]
    

    So I followed along:

    root@server:~# gem install sass
    Successfully installed sass-3.1.15
    1 gem installed
    Installing ri documentation for sass-3.1.15...
    Installing RDoc documentation for sass-3.1.15...
    
    root@server:~# sass
    bash: sass: command not found
    

    Despite looking around like an idiot trying to find some simple way to run something like gem run sass or some other workaround to make it function, I am more or less at a loss.

  • Faisal
    Faisal over 4 years
    if using brew to install ruby the path of ruby gem will be at /usr/local/lib/ruby/gems/*/gems/gem-name/bin/executable-file‌​-name
  • morhook
    morhook almost 4 years
    I had to also clean up the file $HOME/.rbenv/shims/.rbenv-shim to fix this. Posted your solution on the accepted answer.