为什么“rvm 使用"命令需要/建议登录 shell? [英] Why does "rvm use" command require/suggest a login shell?

查看:31
本文介绍了为什么“rvm 使用"命令需要/建议登录 shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 RVM 的默认安装和非登录 shell,执行 rvm use 会产生:

With a default installation of RVM and from a non-login shell, executing rvm use produces:

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.

出现此警告的原因是在安装过程中仅在 ~/.bash_profile 之类的文件中添加了以下源代码行:

Where the reason for this warning is that the following sourcing line is added only in files like ~/.bash_profile during installation:

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

之前的行为甚至可以从 https://rvm.io/support/确认为预期行为常见问题#shell_login:

And the previous can even be confirmed as expected behavior from https://rvm.io/support/faq#shell_login:

默认情况下,RVM 当前将自身添加到 ~/.bash_profile 文件中,并且推荐的方法是在 gnome-terminal 中启用登录 shell(和屏幕).

RVM by default adds itself currently to ~/.bash_profile file, and the recommended way is to enable login shell in gnome-terminal (and screen).

但是,为什么 RVM 安装程序不简单地在 ~/.bashrc 之类的文件中添加上一行,以便 rvm use 之类的命令对登录和非登录都有效?登录shell?.

But, why isn't the RVM installer simply adding the previous line in files like ~/.bashrc so commands like rvm use work both for login and non-login shells?.

没有正确/官方答案的类似问题:

Similar questions without a proper/official answer:

推荐答案

这里的主要原因是 rvm 必须定义为 shell 的函数,而不是 rvm-use 脚本.

The main reason here is that rvm must be defined as a function of your shell and not as a rvm-use script.

如果定义为脚本,rvm-use 将在单独的子进程中运行,并且只能访问您的 shell 环境的副本,而不是原始 env.因为 rvm use 需要实际修改您的本地 PATH 环境(为正确版本添加 rvm ruby​​ shims)它需要完全访问您的 shell 环境 - 因此需要使用函数.

If defined as a script, rvm-use would operate in a separate subprocess and only had an access to a copy of your shell environment, not to the original env. Because rvm use needs to actually modify your local PATH environment (to prepend rvm ruby shims for correct version) it needs full access to your shell environment - hence use of function is required.

这意味着,你需要在某处加载这个函数 - 它(很可能,没有完全检查它)通过 /etc/profile 完成,它加载 /etc/profile.d/rvm.sh 文件.此文件需要手动获取或在终端作为登录 shell 打开时自动加载.

This means, you need to load this function somewhere - it is (most likely, didn't fully check it) done via /etc/profile, which loads /etc/profile.d/rvm.sh file. This file needs to be either manually sourced or is loaded automatically when terminal opens as a login shell.

现在,为什么 rvm 需要修改本地终端环境而不是使用单个全局状态?这是为了让我们可以同时打开几个终端,同时激活不同的 ruby​​ 版本.

Now, why does rvm needs to modify local terminal environment instead of using single global state? It is to allow us to have few terminals open with different ruby versions active at the same time.

这篇关于为什么“rvm 使用"命令需要/建议登录 shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆