ruby - 注销后 RVM 设置丢失

标签 ruby macos

我在 OS X 上安装了 RVM 和 Ruby。我使用以下方法设置默认版本:

rvm use 1.9.3-p194 --default

但这只适用于当前的终端 session 。当我开始一个新 session 时,ruby -v 返回我系统的 Ruby 版本。

有什么提示吗?

UPD

macbook:~ mighter$ rvm info

ruby-1.9.3-p194:

  system:
    uname:       "Darwin macbook.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.8/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
    zsh:         "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"

  rvm:
    version:      "rvm 1.18.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "1 hour 22 minutes 16 seconds ago"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.3p194"
    date:         "2012-04-20"
    platform:     "x86_64-darwin12.2.0"
    patchlevel:   "2012-04-20 revision 35410"
    full_version: "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]"

  homes:
    gem:          "/usr/local/rvm/gems/ruby-1.9.3-p194"
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p194"

  binaries:
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby"
    irb:          "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/irb"
    gem:          "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/gem"
    rake:         "/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin/rake"

  environment:
    PATH:         "/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin"
    GEM_HOME:     "/usr/local/rvm/gems/ruby-1.9.3-p194"
    GEM_PATH:     "/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194@global"
    MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p194"
    IRBRC:        "/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

登录后:

macbook:~ mighter$ rvm info

system:

  system:
    uname:       "Darwin macbook.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.8/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
    zsh:         "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"

  rvm:
    version:      "rvm 1.18.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "1 hour 21 minutes 18 seconds ago"

  homes:
    gem:          "not set"
    ruby:         "not set"

  binaries:
    ruby:         "/usr/bin/ruby"
    irb:          "/usr/bin/irb"
    gem:          "/usr/bin/gem"
    rake:         "/usr/bin/rake"

  environment:
    PATH:         "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""

UPD2

macbook:~ mighter$ cat .bashrc 

PATH=$PATH:/usr/local/rvm/bin # Add RVM to PATH for scripting
macbook:~ mighter$ cat .bash_profile 

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm" # Load RVM into a shell session *as a function*

UPD3

/usr/local/rvm/scripts/rvm
#!/usr/bin/env bash

# rvm : Ruby enVironment Manager
# https://rvm.io
# https://github.com/wayneeseguin/rvm

# also duplicated in scripts/base
__rvm_has_opt()
{
  {
    [[ -n "${ZSH_VERSION}"  ]] && setopt | grep "^${1}$" >/dev/null 2>&1
  } ||
  {
    [[ -n "${BASH_VERSION}" ]] && [[ ":$SHELLOPTS:" =~ ":${1}:" ]]
  } ||
  return 1
}

# Do not allow sourcing RVM in `sh` - it's not supported
# return 0 to exit from sourcing this script without breaking sh
if __rvm_has_opt "posix"
then return 0
fi

# TODO: Alter the variable names to make sense
\export HOME rvm_prefix rvm_user_install_flag rvm_path
HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME

[[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
  rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
     then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  fi

  for rvmrc in "${rvm_rvmrc_files[@]}"
  do
    if [[ -f "$rvmrc" ]]
    then
      if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
      then
        printf "%b" "
Error:
        $rvmrc is for rvm settings only.
        rvm CLI may NOT be called from within $rvmrc.
        Skipping the loading of $rvmrc"
        return 1
      else
        source "$rvmrc"
      fi
    fi
  done
  unset rvm_rvmrc_files
fi

# detect rvm_path if not set
if [[ -z "${rvm_path:-}" ]]
then
  if (( UID == 0 ))
  then
    if (( ${rvm_user_install_flag:-0} == 0 ))
    then
      rvm_user_install_flag=0
      rvm_prefix="/usr/local"
      rvm_path="${rvm_prefix}/rvm"
    else
      rvm_user_install_flag=1
      rvm_prefix="$HOME"
      rvm_path="${rvm_prefix}/.rvm"
    fi
  else
    if [[ -d "$HOME/.rvm" && -s "$HOME/.rvm/scripts/rvm" ]]
    then
      rvm_user_install_flag=1
      rvm_prefix="$HOME"
      rvm_path="${rvm_prefix}/.rvm"
    else
      rvm_user_install_flag=0
      rvm_prefix="/usr/local"
      rvm_path="${rvm_prefix}/rvm"
    fi
  fi
else
  # remove trailing slashes, btw. %%/ <- does not work as expected
  rvm_path="${rvm_path%%+(\/)}"
fi

# guess rvm_prefix if not set
if [[ -z "${rvm_prefix}" ]]
then
  rvm_prefix=$( dirname $rvm_path )
fi

# guess rvm_user_install_flag if not set
if [[ -z "${rvm_user_install_flag}" ]]
then
  if [[ "${rvm_prefix}" == "${HOME}" ]]
  then
    rvm_user_install_flag=1
  else
    rvm_user_install_flag=0
  fi
fi

export rvm_loaded_flag
if [[ -n "${BASH_VERSION:-}" || -n "${ZSH_VERSION:-}" ]] &&
  typeset -f rvm >/dev/null 2>&1
then
  rvm_loaded_flag=1
else
  rvm_loaded_flag=0
fi

if (( ${rvm_loaded_flag:=0} == 0 )) || (( ${rvm_reload_flag:=0} == 1 ))
then
  if [[ -n "${rvm_path}" && -d "$rvm_path" ]]
  then
    true ${rvm_scripts_path:="$rvm_path/scripts"}

    if [[ -f "$rvm_scripts_path/base" ]]
    then
      source "$rvm_scripts_path/base"
    else
      printf "%b" "WARNING:
      Could not source '$rvm_scripts_path/base' as file does not exist.
      RVM will likely not work as expected.\n"
    fi

    __rvm_ensure_is_a_function
    __rvm_setup

    export rvm_version
    rvm_version="$(cat "$rvm_path/VERSION") ($(cat "$rvm_path/RELEASE" 2>/dev/null))"

    alias rvm-restart="rvm_reload_flag=1 source '${rvm_scripts_path:-${rvm_path}/scripts}/rvm'"

    if ! builtin command -v ruby >/dev/null 2>&1 ||
      builtin command -v ruby | GREP_OPTIONS="" \grep -v "${rvm_path}" >/dev/null ||
      builtin command -v ruby | GREP_OPTIONS="" \grep "${rvm_path}/bin/ruby$" >/dev/null
    then
      if [[ -s "$rvm_environments_path/default" && "${rvm_action}" != "switch" ]]
      then
        source "$rvm_environments_path/default"
      elif [[ -s "$rvm_path/environments/default" ]]
      then
        source "$rvm_path/environments/default"
      fi
    fi

    # Makes sure rvm_bin_path is in PATH atleast once.
    __rvm_conditionally_add_bin_path

    if (( ${rvm_reload_flag:=0} == 1 ))
    then
      [[ "${rvm_auto_reload_flag:-0}" == 2 ]] || printf "%b" 'RVM reloaded!\n'
      # make sure we clean env on reload
      __rvm_env_loaded=1
      unset __rvm_project_rvmrc_lock
    fi

    rvm_loaded_flag=1
  else
    printf "%b" "\n\$rvm_path ($rvm_path) does not exist."
  fi
  unset rvm_prefix_needs_trailing_slash rvm_gems_cache_path \
    rvm_gems_path rvm_project_rvmrc_default rvm_gemset_separator rvm_reload_flag
else
  source "${rvm_scripts_path:="$rvm_path/scripts"}/initialize"
  __rvm_setup
fi

if [[ -t 0 && ${rvm_project_rvmrc:-1} -gt 0 ]] &&
  rvm_is_a_shell_function no_warning &&
  ! __function_on_stack __rvm_project_rvmrc &&
  typeset -f __rvm_project_rvmrc >/dev/null 2>&1
then
  # Reload the rvmrc, use promptless ensuring shell processes does not
  # prompt if .rvmrc trust value is not stored.
  rvm_promptless=1 __rvm_project_rvmrc
  rvm_hook=after_cd
  source "${rvm_scripts_path:-${rvm_path}/scripts}/hook"
fi

__rvm_teardown

最佳答案

您的配置文件中可能没有包含 rvm 脚本。如果您以前安装过 rvm,它可能会加载错误的文件,它们的位置与历史版本相比有轻微但重要的变化。

installation documentation建议:

echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile

当然,如果你没有使用 bash 或者你的 .bash_profile 由于某种原因没有被加载,这可能是你的问题的原因。

如果您已经完成了 rvm 的根安装,那么您需要调整该行以包含 /usr/local/scripts/rvm,或者它所在的任何地方安装,并改为更改 /etc/bash_profile

关于ruby - 注销后 RVM 设置丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677639/

相关文章:

macos - 在终端中更改 Pytest 颜色输出

ios - Travis CI 上的 Carthage 缓存

ruby - 为什么不能在 `singleton` `Fixnum` ,`Bignum` ,`Float` 类对象上定义 ,`Symbol` 方法,但 ` FalseClass` 和 `TrueClass` 可以有?

windows - 如何以编程方式检索 Safari 的完整浏览历史记录?

ruby-on-rails - 在 Rails 中以毫秒为单位存储时间

sql - Ruby on Rails where 关系查询

objective-c - 将我的 Mac 应用分发给 friend

macos - 创建分组 TableView

ruby-on-rails - 将子字符串替换为另一个字符串 rails

mysql - Ruby + Sequel + Sinatra + MySQL 连接问题