How do I run a Ruby Gem?
Asked Answered
A

6

31

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.

Arceliaarceneaux answered 20/3, 2012 at 18:31 Comment(2)
What's the output of echo $PATH?Reinertson
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin (though the problem has been solved, see below). Thanks for putting it on the right track though :)Arceliaarceneaux
A
10

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.)

Arceliaarceneaux answered 20/3, 2012 at 19:57 Comment(0)
A
8

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

rbenv rehash

Almanza answered 16/1, 2014 at 16:21 Comment(1)
I had to also clean up the file $HOME/.rbenv/shims/.rbenv-shim to fix this. Posted your solution on the accepted answer.Paulie
K
8

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
Kapellmeister answered 23/3, 2019 at 1:24 Comment(0)
N
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.

Neighborhood answered 20/12, 2018 at 2:13 Comment(1)
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-nameLilongwe
A
0

In my case, I was using MacOS Sonoma M1 and installed Ruby 2.7 via Homebrew.

brew install [email protected]

Set the appropriate bin path in either .zshrc or .bashrc.

export PATH="/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/lib/ruby/gems/2.7.0/bin:$PATH"

You need to install the Ruby Gem.

gem install /path/to/<ruby-gem>.gem

You can then execute ruby gem.

<ruby-gem> -h

See the installation bin path of your ruby gem.

which <ruby-gem>
Amendment answered 28/12, 2023 at 7:50 Comment(0)
L
-2

If you're trying to run a simple WEBrick server for your gem you can do the following after installation:

sass start
Littlefield answered 4/1, 2021 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.