ruby “RVM 不是函数”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9752779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"RVM is not a function" error
提问by Jwosty
RVM is installed on my machine (running Mac OSX 10.6.8), correctly and it runs fine. The odd thing is that to run it, I have to use source ~/.rvm/scripts/rvmfor every new session. I tried making a symlink from it to /opt/local/bin/rvm, but when it runs it does nothing. I also tried creating a symlink from ~/.rvm/bin/rvmto /opt/local/bin/rvm, and when I run rvmin the Terminal it displays the help page, as expected. But when I try rvm use some_ruby_versionit always displays "RVM is not a function, selecting rubies with 'rvm use ...' will not work.". How can I fix this?
RVM 正确安装在我的机器上(运行 Mac OSX 10.6.8)并且运行良好。奇怪的是,要运行它,我必须在source ~/.rvm/scripts/rvm每个新会话中使用它。我尝试从它创建一个符号链接到/opt/local/bin/rvm,但是当它运行时它什么也不做。我还尝试从~/.rvm/bin/rvmto创建符号链接/opt/local/bin/rvm,当我rvm在终端中运行时,它会按预期显示帮助页面。但是当我尝试时rvm use some_ruby_version它总是显示“RVM不是一个功能,选择带有'rvm use ...'的红宝石将不起作用。”。我怎样才能解决这个问题?
My goal is to get it to the the point that I don'thave to type the source command every session, and for some reason ~/.profiledoes not execute.
我的目标是让我不必在每个会话中都键入源命令,并且由于某种原因~/.profile不执行。
采纳答案by Jwosty
I didn't understand what ~/.profiledoes correctly; I needed to change ~/.bash_profileinstead. Problem solved!
我不明白什么~/.profile是正确的;我需要改变~/.bash_profile。问题解决了!
回答by Daniel Pittman
You have to source the RVM script into the current session because it makes changes to the shell environment - and it is absolutely impossible for that to be done from a child process. Your efforts at running RVM as an external command cannot succeed.
您必须将 RVM 脚本输入到当前会话中,因为它会对 shell 环境进行更改 - 而这绝对不可能从子进程中完成。您将 RVM 作为外部命令运行的努力不会成功。
To actually fix this you have two choices:
要实际解决此问题,您有两种选择:
- Configure your terminal emulator to start a login shell, rather than a non-login shell, so that your
.profileis loaded. - Modify
.bashrcto source RVM instead, which works for non-login shells as well.
- 配置您的终端模拟器以启动登录 shell,而不是非登录 shell,以便
.profile加载您的。 .bashrc改为修改源 RVM,这也适用于非登录 shell。
To do the second you can just add to ~/.bashrc:
要执行第二个操作,您只需添加到~/.bashrc:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
回答by Alberto Fortes
If you are using zsh as shell instead bash, you have to:
如果您使用 zsh 作为 shell 而不是 bash,则必须:
1.
1.
vi ~/.zshrc
2. Like Matt said, add:
2. 就像马特说的,添加:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
3. Restart Terminall 4. Done!
3. 重启终端 4. 完成!
rvm use 1.9.3
Wil work
威尔工作
回答by damusix
Well, with mountain lion (10.8.3) what worked for me was editing /etc/profile
好吧,对于山狮(10.8.3),对我有用的是编辑 /etc/profile
and adding the line mentioned before at the bottom of the file:
并在文件底部添加前面提到的行:
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi
回答by okcomputer
I had the same issue. I found the .profile file was not getting updated, so i added the same command that was added into .bash_profile:
我遇到过同样的问题。我发现 .profile 文件没有更新,所以我添加了与 .bash_profile 相同的命令:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && 源 "$HOME/.rvm/scripts/rvm"
I don't know if this is the right way, but it worked...
我不知道这是否是正确的方法,但它有效......
回答by DWils
You shouldn't need to edit anything as others suggest. Just go into your terminal's settings and select the "Run command as login shell". This will cause .profile to run on the next terminal instance. Reopen your terminal and you should be able to use rvm use 1.9.3(or whatever version you installed).
您不需要像其他人建议的那样编辑任何内容。只需进入终端的设置并选择“以登录外壳运行命令”。这将导致 .profile 在下一个终端实例上运行。重新打开您的终端,您应该可以使用rvm use 1.9.3(或您安装的任何版本)。
More info found on rvm.io (which is also a great place for answers)
在 rvm.io 上找到了更多信息(这也是一个寻找答案的好地方)
回答by Nick Res
What was screwing me up was assuming my path was correct since I was using one I can run manually.
搞砸我的是假设我的路径是正确的,因为我使用的是可以手动运行的路径。
Apparently there are different executables or scripts that can be used and are located in different places.
显然有不同的可执行文件或脚本可以使用并且位于不同的地方。
I thought that the path Mina should use was this:
我认为 Mina 应该使用的路径是这样的:
/usr/local/rvm/bin/rvm
When in reality it was this:
实际情况是这样的:
/usr/local/rvm/scripts/rvm
回答by Ramiz Raja
You have to make some settings.
您必须进行一些设置。
Open terminal and run this command.
打开终端并运行此命令。
source ~/.rvm/scripts/rvm
and then go to edit > Title and commandand check Run command as login shell
然后去edit > Title and command检查Run command as login shell
and you are done. Now you don't need to specify source everytime.
你就完成了。现在您不需要每次都指定来源。
回答by look
I had this issue when I became root. I tried many of the solutions above. What finally worked was exiting from root and being a regular user. Which is what I needed anyway.
当我成为 root 时,我遇到了这个问题。我尝试了上面的许多解决方案。最终奏效的是从 root 退出并成为普通用户。无论如何,这就是我所需要的。
回答by jeffreynolte
None of these solutions seemed to redeem my problem which was on Ubuntu 12.04 LTS.
这些解决方案似乎都无法解决我在 Ubuntu 12.04 LTS 上的问题。
What I did is the following:
我所做的是以下内容:
rvm get stable --auto-dotfilesas outlined in the RVM documentation here- Added
source ~/.profileas the first line of: ~/.bash_profile
rvm get stable --auto-dotfiles作为RVM文档中列出这里- 添加
source ~/.profile为第一行:~/.bash_profile
I will not all of these steps were documented as errors from the RVM command line:
我不会将所有这些步骤都记录为来自 RVM 命令行的错误:
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 --loginas the command. Please visit https://rvm.io/integration/gnome-terminal/for a example.
RVM 不是一个函数,选择带有“rvm use ...”的红宝石将不起作用。您需要更改终端模拟器首选项以允许登录 shell。有时需要
/bin/bash --login作为命令使用。请访问https://rvm.io/integration/gnome-terminal/获取示例。
and
和
WARNING: You have '~/.profile' file, you might want to load it, to do that add the following line to '/home/user_name/.bash_profile':
source ~/.profile
警告:您有“~/.profile”文件,您可能想要加载它,为此将以下行添加到“/home/user_name/.bash_profile”:
源 ~/.profile

