How to install a gem globally without sudo using rbenv?
Asked Answered
A

2

7

I am using rbenv and I am trying to install sass without success.

So, I installed rbenv via Homebrew, then Ruby 2.2 (rbenv install 2.2) and finally gem install sass, but I was unable to make sass available on my $PATH.

Short on time, I sudo gem install sass using my system's (Yosemite) default Ruby 2. This put everything in /Library/Ruby/Gems/2.0.0 and things do work, but not in the most desireable way.

Ideally, using rbenv I should be able to install any Ruby version and have gems installed inside that version's directory and later symlinked to /usrl/local/bin.

Any help as to what could have gone wrong would be very much appreciated.

Ankney answered 6/3, 2015 at 1:4 Comment(1)
Please update your question title if you believe the answer below answers your intended question. The title is not commensurate with the answer.Geis
A
9

Basically, the problem was I did not add rbenv/bin/rbenv to $PATH.

export PATH="$HOME/.rbenv/bin:$PATH"

Better yet, add this to your .bashrc or .bash_profile to start every session with rbenv.

After that, make sure to:

eval "$(rbenv init -)"

In order to enable shims and autocompletion.

fishshell

For those using fish, you can accomplish the same like this:

if status --is-interactive
  . (rbenv init - | psub)
end

Now, if you don't like modifying $PATH directly and have ownership over /usr/local/bin, a more nifty solution is to symlink with ~/.rbenv/bin/rbenv.

 ln -s ~/.rbenv/bin/rbenv /usr/local/bin

ruby-build

As a final warning, make sure to install ruby-build (a rbenv plugin to add the install command to rbenv and be able to easily install Ruby versions.)

If you are using homebrew it's easy as pie:

brew install ruby-build
Ankney answered 7/3, 2015 at 7:24 Comment(1)
Either the question title is wrong, or this "answer" does not address the question.Geis
P
0

Another possible option that may be of relevance for some here, depending on how one thinks about something being "globally" installed, is — assuming one is using the rbenv-based version of the gem command — to use the --user-install option to gem install. E.g.:

gem install --user-install sass

This will install things only for the user running it (so not global in that sense), but also in a way where it's not just available to a particular bundle-based install, say (so it is global in that sense).

Patmos answered 21/9, 2023 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.