从我的 Ubuntu .profile 获取 rvm 只能手动工作,不能在登录时工作

发布于 2024-09-29 02:47:24 字数 330 浏览 0 评论 0原文

我在从 Ubuntu 10.04 .profile 获取 Ruby Version Manager rvm 时遇到问题。代码:

[[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"

...永远不会执行我期望的操作(即,当我打开新 shell 或启动新会话时给我 rvm 程序);但如果我

source .profile

登录后在新的 shell 中执行,它就会起作用!为什么我手动获取它时可以工作,但登录时不能自动工作?

I'm having trouble getting the Ruby Version Manager rvm to source from my Ubuntu 10.04 .profile. The code:

[[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"

...never does what I expect it to (i.e. give me the rvm program when I open a new shell or start a new session); but if I execute

source .profile

in a new shell after logging in, it works! Why will it work when I manually source it, but not automatically at login?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

完美的未来在梦里 2024-10-06 02:47:24

Ubuntu 处理登录脚本的方式似乎与大多数其他 Linux 发行版不同

http:// ubuntuforums.org/showpost.php?p=9127226&postcount=6

上面的帖子暗示 Ubuntu 中的 GDM 登录不会像大多数其他 Linux 发行版那样处理 .bash_profile 或 .profile。我不得不将加载 RVM 的行放入 ~/.bashrc 中,但这还没有引起任何问题。

It would appear that Ubuntu handles it's logon scripts differently than most other linux distros

http://ubuntuforums.org/showpost.php?p=9127226&postcount=6

The above post has hints that GDM logins in Ubuntu don't process .bash_profile or .profile the way most other linux distros do. I have had to put the line loading RVM in the ~/.bashrc and that has not caused any problems yet.

自此以后,行同陌路 2024-10-06 02:47:24

获取 $HOME/.rvm 假定您已经以单个用户安装了 RVM,特别是主目录为 $HOME 的用户。很可能,在您的 Ubuntu 系统上,RVM 已在系统范围内安装,因此您必须按如下方式获取 RVM 脚本:

在您的 .bashrc 文件中添加:

\# Set rvm path

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"

在此行之前;该行将退出并且不执行任何过去的事情,这对于交互式登录来说很好,但如果您使用非交互式 SSH 登录来实现自动化目的,则会出现问题。

\# If not running interactively, don't do anything

[ -z "$PS1" ] && return

Sourcing $HOME/.rvm assumes you have installed RVM a single user, specially, the user whose home directory is $HOME. Likely, on your Ubuntu system, RVM has been installed system wide, and thus you must source the RVM scripts as such:

In your .bashrc file add:

\# Set rvm path

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"

before this line; this line will exit and not execute anything past it, which is fine for interactive logins, bit would be a problem is you are using non-interactive SSH logins for automation purposes.

\# If not running interactively, don't do anything

[ -z "$PS1" ] && return
暖心男生 2024-10-06 02:47:24

RVM 安装页面有一系列需要检查的内容来测试 RVM 的初始化。请阅读 RVM 安装页面末尾的“安装疑难解答”部分。

另外,这里还有 Bash 如何读取其启动文件的描述< /a> 可以帮助解决此类问题。

The RVM installation page has a series of things to check to test the initialization of RVM. Read the "Troubleshooting your Install" section at the end of the RVM installation page.

Also, here's a description of how Bash reads its startup files which can help with this sort of problem.

暗藏城府 2024-10-06 02:47:24

我遇到了 Atom 编辑器无法选择 RVM 环境的问题,因此在 Ubuntu 16.04 上找不到 rubocop 命令。但当我从 gnome 终端启动 Atom 时,问题并不存在。我发现您应该在 .profile 中加载的 RVM 脚本 ~/.rvm/scripts/rvm 开头有以下几行:

if
  builtin test -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" -o -n "${KSH_VERSION:-}"
then
  ...
else
  return 0
fi

奇怪的是,当在登录时执行时,我发现 $BASH_VERSION 为空(而在 gnome 终端中它类似于 4.3.46(1)-release),因此脚本会提前返回,导致 RVM 未正确加载。我尝试将 BASH_VERSION 设置为任何值,效果很好。

以下是我的 .profile 中加载 RVM 的完整代码:

local rvm_home="${HOME}/.rvm"
export PATH="$PATH:${rvm_home}/bin"
if [ -z "$BASH_VERSION" ]; then
    export BASH_VERSION=4
fi
source "${rvm_home}/scripts/rvm"

I had a problem with Atom editor not picking up RVM environment and thus not finding rubocop command on Ubuntu 16.04. But the problem was not there when I started Atom from gnome terminal. What I've found was that RVM script ~/.rvm/scripts/rvm that you're supposed to be loading in your .profile has these lines at the beginning:

if
  builtin test -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" -o -n "${KSH_VERSION:-}"
then
  ...
else
  return 0
fi

Strangely, when executed at login, I've found $BASH_VERSION to be empty (while in gnome terminal it's sth like 4.3.46(1)-release), so the script would do early return leaving RVM not loaded properly. I tried to set BASH_VERSION to whatever and it worked fine.

Here is the complete code from my .profile that loads RVM:

local rvm_home="${HOME}/.rvm"
export PATH="$PATH:${rvm_home}/bin"
if [ -z "$BASH_VERSION" ]; then
    export BASH_VERSION=4
fi
source "${rvm_home}/scripts/rvm"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文