从我的 Ubuntu .profile 获取 rvm 只能手动工作,不能在登录时工作
我在从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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.
获取 $HOME/.rvm 假定您已经以单个用户安装了 RVM,特别是主目录为 $HOME 的用户。很可能,在您的 Ubuntu 系统上,RVM 已在系统范围内安装,因此您必须按如下方式获取 RVM 脚本:
在您的 .bashrc 文件中添加:
在此行之前;该行将退出并且不执行任何过去的事情,这对于交互式登录来说很好,但如果您使用非交互式 SSH 登录来实现自动化目的,则会出现问题。
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:
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.
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.
我遇到了 Atom 编辑器无法选择 RVM 环境的问题,因此在 Ubuntu 16.04 上找不到
rubocop
命令。但当我从 gnome 终端启动 Atom 时,问题并不存在。我发现您应该在.profile
中加载的 RVM 脚本~/.rvm/scripts/rvm
开头有以下几行:奇怪的是,当在登录时执行时,我发现
$BASH_VERSION
为空(而在 gnome 终端中它类似于4.3.46(1)-release
),因此脚本会提前返回,导致 RVM 未正确加载。我尝试将BASH_VERSION
设置为任何值,效果很好。以下是我的
.profile
中加载 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:Strangely, when executed at login, I've found
$BASH_VERSION
to be empty (while in gnome terminal it's sth like4.3.46(1)-release
), so the script would do early return leaving RVM not loaded properly. I tried to setBASH_VERSION
to whatever and it worked fine.Here is the complete code from my
.profile
that loads RVM: