Skip to content

Instantly share code, notes, and snippets.

@arashm
Created February 3, 2013 09:31
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save arashm/4701056 to your computer and use it in GitHub Desktop.
Save arashm/4701056 to your computer and use it in GitHub Desktop.
migrate GEMs from rbenv cache to the newer version of ruby (without internet) Thanks to Austin Ziegler - http://stackoverflow.com/questions/13649241/copying-gems-from-previous-version-of-ruby-in-rbenv
#!/bin/sh
# if you're using ZSH, change the shebang above to "#!/bin/zsh -i"
if [ ${#} -ne 2 ]; then
echo >&2 Usage: $(basename ${0}) old-version new-version
exit 1
fi
home_path=$(cd ~; pwd -P)
old_version=${1}
new_version=${2}
rbenv shell ${old_version}
declare -a old_gem_paths old_gems
old_gem_paths=($(gem env gempath | sed -e 's/:/ /'))
rbenv shell ${new_version}
for ogp in "${old_gem_paths[@]}"; do
case "${ogp}" in
${home_path}/.gem/ruby*|*/.gem/ruby*)
# Skip ~/.gem/ruby.
continue
;;
esac
for old_gem in $(ls -L ${ogp}/cache/*.gem); do
gem install --local --ignore-dependencies ${old_gem}
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment