[英]RVM + Zsh “RVM is not a function, selecting rubies with 'rvm use …' will not work”
I'll start by saying I'm not an expert at command-line, so I really only barely know what I'm doing.我首先要说我不是命令行专家,所以我真的只是几乎不知道我在做什么。
I cannot get RVM and oh-my-zsh to play nice together.我无法让 RVM 和 oh-my-zsh 一起玩得很好。 I've tried several different solutions posted around, some on SO, but nothing I have found seems to fix the issue.
我已经尝试了几种不同的解决方案,其中一些是在 SO 上发布的,但我没有发现似乎可以解决问题。
Initially, someone else setup RVM on my machine.最初,其他人在我的机器上设置了 RVM。 I later setup oh-my-zsh myself, and remember having a lot of trouble doing so.
后来我自己设置了 oh-my-zsh,记得这样做有很多麻烦。
My .zhsrc
file is completely default except for these 2 lines除了这两行,我的
.zhsrc
文件是完全默认的
export PATH=$HOME/bin:/usr/local/bin:/usr/local/rvm/bin:$PATH
#pretty sure this line does nothing, although I've seen this fix around
# several places. I noticed that I don't seem to have an .rvm file in my
# home directory which would be an issue, but I have no idea how to
# go about correcting this.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
I added the /usr/local/rvm
to the Path directive as zsh returns zsh: rvm command not found
without it there.我将
/usr/local/rvm
到 Path 指令中,因为 zsh 返回zsh: rvm command not found
without it there。 Otherwise most rvm command work, with the exception of rvm use
which throws the following error:否则,大多数 rvm 命令都可以工作,但
rvm use
会引发以下错误:
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 a example.
I have ensured the profile preferences on my profile in iTerm2 are set to "Login Shell" as recommended by RVM我已确保按照 RVM 的建议将 iTerm2 中我的个人资料中的个人资料首选项设置为“登录外壳”
I have tried changing these preferences to the "Command" option and using the recommended /bin/bash/ --login
as the command, however zsh no longer appears to work when this happens.我尝试将这些首选项更改为“命令”选项并使用推荐的
/bin/bash/ --login
作为命令,但是当发生这种情况时 zsh 似乎不再起作用。 Changing the command to /bin/zsh/ --login
allows zsh to work again but does not solve the problem as I still get the "RVM is not a function" error when trying to run rvm use
将命令更改为
/bin/zsh/ --login
允许 zsh 再次工作,但没有解决问题,因为在尝试运行rvm use
时我仍然收到“RVM 不是函数”错误
The default ruby in RVM is set to 2.0.0. RVM 中的默认 ruby 设置为 2.0.0。 I can run
ruby -v
in my home folder and get the ruby version output which shows the default version.我可以在我的主文件夹中运行
ruby -v
并获取显示默认版本的 ruby 版本输出。
Working on rails projects, I can run all rails commands IF the Gemfile specifies ruby 2.0.0, the default.处理 rails 项目时,如果 Gemfile 指定 ruby 2.0.0(默认值),我可以运行所有 rails 命令。 However on a project that uses a different version, I get the following error:
但是,在使用不同版本的项目中,出现以下错误:
Your Ruby version is 2.0.0, but your Gemfile specified 1.9.3
Then I cannot run rvm use 1.9.3
as it returns the above mentioned error.然后我无法运行
rvm use 1.9.3
因为它返回上述错误。
Some info about my setup:关于我的设置的一些信息:
For me, I just had to add对我来说,我只需要添加
source $HOME/.rvm/scripts/rvm
to my ~/.zshrc and it started working, after having the same error message as in this SO question.到我的 ~/.zshrc 并开始工作,在收到与此 SO 问题相同的错误消息后。
Turns out that RVM was installed in the wrong place.原来 RVM 安装在错误的地方。 When I had initially installed RVM I believe I did so with the
sudo
command, which ran the multi-user install (installed to /usr/local/rvm
), and not the single user (should be in ~/.rvm/scrips/rvm
), which is why all the posted solutions were not working for me.当我最初安装 RVM 时,我相信我是使用
sudo
命令完成的,该命令运行多用户安装(安装到/usr/local/rvm
),而不是单用户安装(应该在~/.rvm/scrips/rvm
),这就是为什么所有发布的解决方案都不适合我的原因。
I had to uninstall RVM with rvm implode
.我不得不用
rvm implode
卸载 RVM。 There were some permissions issues, so I had to manually go in and delete the files that could not be deleted.有一些权限问题,所以我不得不手动进去删除无法删除的文件。 Ran the curl command to re-install RVM and now it's installed in the correct place.
运行 curl 命令重新安装 RVM,现在它已安装在正确的位置。
Sourcing RVM in my .zshrc
with [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
now works properly and I can switch between rubies.在我的
.zshrc
使用[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
在我的[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
采购 RVM 现在可以正常工作,我可以在红宝石之间切换。
@trustkr's answer worked for me, but would like to add... @trustkr 的回答对我有用,但想补充...
I ran into this issue immediately after install of rvm.安装rvm后我立即遇到了这个问题。 In order for the
为了使
source
to work in in the ~/.zshrc file to work, you will need either start a new terminal session and work there OR you can run要在 ~/.zshrc 文件中工作,您需要启动一个新的终端会话并在那里工作,或者您可以运行
source ~/.rvm/scripts/rvm
in the same terminal session in which you installed.在您安装的同一个终端会话中。
[Mac OS 10.10.5 - iTerm - zsh] [Mac OS 10.10.5 - iTerm - zsh]
I had the same issue added this one line at end of .zshrc file我有同样的问题在 .zshrc 文件的末尾添加了这一行
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
and works now everything works fine on my ubuntu 16.04 operating system :)并且现在在我的 ubuntu 16.04 操作系统上一切正常:)
You need to run the following:您需要运行以下命令:
$ source ~/.rvm/scripts/rvm
$ source ~/.rvm/scripts/rvm
then run this然后运行这个
$ type rvm |
$ 类型 rvm | head -n 1
头-n 1
and the result will be like结果会像
rvm is a shell function from /home/sun/.rvm/scripts/cli
rvm 是 /home/sun/.rvm/scripts/cli 中的 shell 函数
Hope that helps!希望有帮助!
Another solution :另一种解决方案:
1) In the terminal run : 1)在终端运行:
which rvm
The output in my case is ---> /usr/share/rvm在我的情况下,输出是 ---> /usr/share/rvm
2) Open .zshrc file 2) 打开 .zshrc 文件
nano ~/.zshrc
add " source + the_path_to_your_rvm + /scripts/rvm ", in my case it's :添加“ source + the_path_to_your_rvm + /scripts/rvm ”,在我的情况下是:
source /usr/share/rvm/scripts/rvm
3) save the file (.zshrc) 3)保存文件(.zshrc)
4) close the terminal and open it again 4)关闭终端并再次打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.