Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install after the fact #6

Open
kevinSuttle opened this issue Mar 13, 2013 · 7 comments
Open

Install after the fact #6

kevinSuttle opened this issue Mar 13, 2013 · 7 comments

Comments

@kevinSuttle
Copy link

For some reason, rbenv-default-gems didn't run at some point, and so my gems aren't installed. I tried to install them by running the install script by itself. Here's the output in zsh:

☰  bash install/default-gems.bash
rbenv: rbenv-default-gems plugin requires ruby-build 20130129 or later

I've got the latest Rbenv and Ruby-build repos. I'm not sure if the script was intended to be used this way, but it'd be nice to have just in case.

@exalted
Copy link

exalted commented Mar 15, 2013

@kevinSuttle agreed! Same here… I was so disappointed when I didn’t get my sweet gems installed automagically. Clearly there’s some room to improvements on this plugin.

Note: I installed using homebrew (even though it isn’t the recommended way of doing it), because I personally prefer installing such things that way whenever it is possible.

@kevinSuttle
Copy link
Author

I also install via Homebrew. I just like the convenience of automation.

@farfanoide
Copy link

didn't work for me either (also installed it via homebrew)

@teleservices
Copy link

I installed straight from github but experienced the same error trying to call it directly. My ruby-build is version 20140408 which is higher that required.

Having a look at the code it might be split up and another method besides the "after_install" event could be created to allow direct access to the install_default_gems() function. Also the status check should be moved out of the install_default_gems() function.

Then the install_default_gems() function would be able to stand on its own so it cold be called any time you want to update your gems from the list of default gems for your currently selected ruby.

@bronson
Copy link

bronson commented Jun 19, 2014

Totally agree. How do I update my existing rubies when I modify ~/default-gems?

I made this change:

diff --git a/etc/rbenv.d/install/default-gems.bash b/etc/rbenv.d/install/default-gems.bash
index a8a9a6a..540fadf 100644
--- a/etc/rbenv.d/install/default-gems.bash
+++ b/etc/rbenv.d/install/default-gems.bash
@@ -1,9 +1,3 @@
-if declare -Ff after_install >/dev/null; then
-  after_install install_default_gems
-else
-  echo "rbenv: rbenv-default-gems plugin requires ruby-build 20130129 or later" >&2
-fi
-
 install_default_gems() {
   # Only install default gems after successfully installing Ruby.
   [ "$STATUS" = "0" ] || return 0
@@ -34,10 +28,16 @@ install_default_gems() {
       # Invoke `gem install` in the just-installed Ruby. Point its
       # stdin to /dev/null or else it'll read from our default-gems
       # file.
-      RBENV_VERSION="$VERSION_NAME" rbenv-exec gem install "$gem_name" "${args[@]}" < /dev/null || {
+      RBENV_VERSION="$VERSION_NAME" rbenv exec gem install "$gem_name" "${args[@]}" < /dev/null || {
         echo "rbenv: error installing gem \`$gem_name'"
       } >&2

     done < "${RBENV_ROOT}/default-gems"
   fi
 }
+
+if declare -Ff after_install >/dev/null; then
+  after_install install_default_gems
+else
+  VERSION_NAME="$(rbenv version-name)" RBENV_ROOT="$(rbenv root)" STATUS=0 install_default_gems
+fi

And ran

bash .rbenv/plugins/rbenv-default-gems/etc/rbenv.d/install/default-gems.bash

Worked great! Gems are installed, and rbenv-install continues working as before.

It shouldn't be too hard to expand this into a proper 'rbenv install default-gems' command.

@bronson
Copy link

bronson commented Oct 27, 2014

FWIW, I'm now running chruby with https://github.com/bronson/chruby-default-gems

That includes a command to install gems after the fact. :)

@amiel
Copy link

amiel commented Jun 4, 2024

It would be great if rbenv-default-gems could add a command to rbenv to trigger reinstalling.

In the meantime, this worked for me:

bash -c 'source /opt/homebrew/opt/rbenv/plugins/rbenv-default-gems/etc/rbenv.d/install/default-gems.bash;STATUS=0;install_default_gems'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants