“RVM is not a function” error

扶醉桌前 提交于 2019-12-02 16:16:17
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.

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

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

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

damusix

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

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

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

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.

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

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.

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

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