#!/usr/bin/env bash source "$rvm_scripts_path/base" result=0 __rvm_become rubygems_setup() { __rvm_warn_on_rubyopt unset RUBYOPT if [[ ! -z "$(echo $rvm_ruby_version | awk '/^1\.9/')" ]] || [[ ! -z "$(echo $rvm_ruby_interpreter | awk '/^mput/')" ]] ; then install=0 elif [[ "$rvm_ruby_string" = "ruby-head" ]] ; then install=0 elif [[ -n "$(echo "$rvm_ruby_string" | awk '/^rbx|jruby|rubinius/')" ]]; then install=0 else install=1 fi if [[ "$install" -eq 0 ]] ; then $rvm_scripts_path/log "error" "Cannot switch to ${version} for this interpreter." exit 1 else $rvm_scripts_path/log "info" "Removing old Rubygems files..." rubygems_dir="$(ruby -rrbconfig -e "puts Config::CONFIG.values_at('sitelibdir','vendorlibdir').detect {|path| File.directory?(File.join(path, 'rubygems')) }.to_s")" if [[ -n "$rubygems_dir" && -d "$rubygems_dir" ]]; then # Remove common files installed by ruby gems. rm -rf "${rubygems_dir}/ubygems.rb" "${rubygems_dir}/rubygems.rb" "${rubygems_dir}/rubygems" "${rubygems_dir}/gauntlet_rubygems.rb" fi $rvm_scripts_path/log "info" "Installing rubygems dedicated to $rvm_ruby_string..." rvm_rubygems_version="$version" rvm_gem_package_name="rubygems-$rvm_rubygems_version" rvm_rubygems_url=$(__rvm_db "rubygems_${rvm_rubygems_version}_url") rvm_gem_url="$rvm_rubygems_url/$rvm_gem_package_name.tgz" # Sanity check... If setup.rb is missing from the rubygems source path, # something went wrong. Cleanup, aisle 3! if [[ ! -f "$rvm_src_path/$rvm_gem_package_name/setup.rb" ]]; then rm -rf "$rvm_src_path/$rvm_gem_package_name" fi if [[ ! -d "$rvm_src_path/$rvm_gem_package_name" ]] ; then $rvm_scripts_path/log "info" "Retrieving $rvm_gem_package_name" $rvm_scripts_path/fetch "$rvm_gem_url" result=$? ; if [[ "$result" -gt 0 ]] ; then $rvm_scripts_path/log "error" "There has been an error while trying to fetch the source. Aborting the installation." ; __rvm_pushpop ; return $result fi mkdir -p "$rvm_src_path/$rvm_gem_package_name" __rvm_run "rubygems.extract" "cat $rvm_archives_path/$rvm_gem_package_name.tgz | gunzip | tar xf - -C $rvm_src_path" "Extracting $rvm_gem_package_name ..." fi builtin cd "$rvm_src_path/$rvm_gem_package_name" __rvm_run "rubygems.install" "GEM_PATH=$rvm_ruby_gem_path GEM_HOME=$rvm_ruby_gem_home BUNDLE_PATH=$rvm_ruby_gem_home $rvm_ruby_home/bin/ruby $rvm_src_path/$rvm_gem_package_name/setup.rb" "Installing rubygems for $rvm_ruby_home/bin/ruby" result=$? if [[ "$result" == 0 ]] ; then $rvm_scripts_path/log "info" "Installation of rubygems $rvm_ruby_package_name completed successfully." else $rvm_scripts_path/log "warning" "Installation of rubygems $rvm_ruby_package_name did not complete successfully." fi if [[ ! -z "$rvm_major_version" ]] ; then ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/${rvm_release_version}.${rvm_major_version}" else ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/$interpreter" fi fi # Add ruby's gem path to ruby's lib direcotry. mkdir -p "$(dirname $ruby_lib_gem_path)" if [[ -d "$ruby_lib_gem_path" ]] ; then rm -rf "$ruby_lib_gem_path" ; fi ln -nfs "$rvm_ruby_gem_home" "$ruby_lib_gem_path" unset ruby_lib_gem_path } if ! command -v ruby > /dev/null ; then $rvm_scripts_path/log "error" "'ruby' was not found, cannot install rubygems unless ruby is present (Do you have an RVM ruby installed & selected?)" exit 1 fi # # rvm rubygems use X # if [[ $# -gt 0 ]] ; then version="$1" ; shift args="$(echo "$@" | __rvm_strip)" else $rvm_scripts_path/log "error" "A version must be specified, for example 'rvm rubygems 1.3.7'" exit 1 fi rubygems_setup exit $result