Xkeeper
Xkeeper

Reputation: 1085

How do I run a Ruby Gem?

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.

Upvotes: 32

Views: 27073

Answers (6)

ARKhan
ARKhan

Reputation: 1975

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>

Upvotes: 0

fireball.1
fireball.1

Reputation: 1521

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

sass start

Upvotes: -2

William Entriken
William Entriken

Reputation: 39263

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.

Upvotes: 6

ShaulF
ShaulF

Reputation: 890

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

Upvotes: 9

cirovladimir
cirovladimir

Reputation: 613

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

rbenv rehash

Upvotes: 8

Xkeeper
Xkeeper

Reputation: 1085

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

Upvotes: 11

Related Questions