“RVM is not a function” error

不羁的心 提交于 2019-12-20 08:35:43

问题


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/rvm for 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/rvm to /opt/local/bin/rvm, and when I run rvm in the Terminal it displays the help page, as expected. But when I try rvm use some_ruby_version it always displays "RVM is not a function, selecting rubies with 'rvm use ...' will not work.". How can I fix this?

My goal is to get it to the the point that I don't have to type the source command every session, and for some reason ~/.profile does not execute.


回答1:


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.

To actually fix this you have two choices:

  1. Configure your terminal emulator to start a login shell, rather than a non-login shell, so that your .profile is loaded.
  2. Modify .bashrc to source RVM instead, which works for non-login shells as well.

To do the second you can just add to ~/.bashrc:

if test -f ~/.rvm/scripts/rvm; then
    [ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi



回答2:


If you are using zsh as shell instead bash, you have to:

1.

vi ~/.zshrc 

2. Like Matt said, add:

if test -f ~/.rvm/scripts/rvm; then
   [ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi

3. Restart Terminall 4. Done!

rvm use 1.9.3

Wil work




回答3:


I didn't understand what ~/.profile does correctly; I needed to change ~/.bash_profile instead. Problem solved!




回答4:


Well, with mountain lion (10.8.3) what worked for me was editing /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



回答5:


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:

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

I don't know if this is the right way, but it worked...




回答6:


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).

More info found on rvm.io (which is also a great place for answers)

https://rvm.io/integration/gnome-terminal




回答7:


You have to make some settings.

Open terminal and run this command.

source ~/.rvm/scripts/rvm

and then go to edit > Title and command and check Run command as login shell

and you are done. Now you don't need to specify source everytime.




回答8:


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:

 /usr/local/rvm/bin/rvm

When in reality it was this:

/usr/local/rvm/scripts/rvm



回答9:


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.




回答10:


None of these solutions seemed to redeem my problem which was on Ubuntu 12.04 LTS.

What I did is the following:

  1. rvm get stable --auto-dotfiles as outlined in the RVM documentation here
  2. Added source ~/.profile as the first line of: ~/.bash_profile

I will not all of these steps were documented as errors from the RVM command line:

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.

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



来源:https://stackoverflow.com/questions/9752779/rvm-is-not-a-function-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!