217

List the ruby versions

console:~$ rvm list

rvm rubies

ruby-2.0.0-p481 [ i686 ]

# => - current
# =* - current && default
#  * - default

Try to use a specific version of ruby

console:~$ rvm use 2.0.0

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.
9
  • 1
    What are you trying to do?
    – Pavan
    May 30, 2014 at 20:37
  • 1
    What terminal do you use? Setting the login shell differs per terminal application. Alternatively you could source $HOME/.profile or source $HOME/.bash_profile where rvm has probably defined its init line. May 30, 2014 at 20:37
  • You need to run your console as a login shell. What system do you have?
    – BroiSatse
    May 30, 2014 at 20:38
  • Terminal Gnome the Ubuntu 12.04 lts May 30, 2014 at 21:16
  • 6
    In case you are wondering what the difference between a login vs non-login shell: unix.stackexchange.com/questions/38175/…
    – stephenbez
    Mar 5, 2015 at 7:33

15 Answers 15

288

Your console is not running as a login shell and hence have no access to rvm function. If you are running Ubuntu, you can:

  1. Open console
  2. Select Edit -> Profile Preferences
  3. Select tab: Title and Command
  4. Check box 'Run command as a login shell'
  5. Restart terminal
7
  • 1
    I did that but did not work. The problem persists . How to remove rvm completely? May 30, 2014 at 21:13
  • 23
    Of course you will need the following in your ~/.profile [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" Sep 3, 2014 at 4:30
  • 4
    I think this could be explained more ― "and hence have no access to rvm function"
    – matanox
    Sep 17, 2016 at 6:15
  • 1
    It worked. Bu can you tell the difference between those two? Mar 14, 2017 at 16:22
  • 9
    What works for me on OSX is /bin/bash --login; source ~/.rvm/scripts/rvm; rvm use 2.4.0
    – Jayesh
    Sep 16, 2017 at 12:11
156

Type bash --login from your terminal. And then give rvm use 2.0.0

3
  • @AdityaPednekar So, sometimes reading the error/console message actually helps, 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. specifies the details. Jul 10, 2018 at 10:02
  • 4
    Yeah, It helps realize how unreasonably complex it is to use rvm compared to nvm Apr 30, 2020 at 16:09
  • 1
    Thanks this worked for me and it saved lot of time. Mar 25, 2021 at 8:26
93

It seems like your rvm does not load ".bash_profile" properly. I have done to fix it in MAC OS X or Ubuntu 14.04 by opening terminal and write:

source ~/.rvm/scripts/rvm
1
  • In my case I was on new m1 macos with zsh as default shell and had to instead add that line to .zprofile Jul 8, 2022 at 15:15
59

My env is OSX Yosemite. Had the same issue .... solved by adding the following

1) edit and add the following line to .bash_profile file.

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

2) Restart terminal and try RVM command again

2
  • 5
    You can add this to ~/.bashrc or ~/.zshrc (if your are using zsh) too.
    – adridev
    Feb 4, 2015 at 20:33
  • If you don't want or cannot restart the terminal, you can run source ~/.bash_profile after editing it. Jun 18, 2020 at 15:23
48

If you don't want that every time you open a terminal, do the suggestion above again, just add

source ~/.rvm/scripts/rvm

at the end of ~/.bashrc

3
  • This one helped. Apr 4, 2019 at 13:19
  • .. and needs a restart ?
    – gordie
    Feb 27, 2020 at 23:04
  • @gordie Nope, simply execute source ~/.bashrc Sep 5, 2020 at 22:50
27

The error is due to rvm is not running as in login shell. Hence try the below command:

/bin/bash --login

You will able run rvm commands instantly as login shell in terminal.

16

Same principle as other answers, just thought it was quicker than re-opening terminals :)

bash -l -c "rvm use 2.0.0"
1
  • Someone should come up with a better answer than all of these. This is the only item in all the answers to this question that works for me but this is not something I want to do all the time. Im on Mac OSX Sierra
    – djangofan
    Jun 22, 2017 at 1:06
12

You need to add source ~/.rvm/scripts/rvm to ~/.your_shellrc file. From now when you load a shell, rvm will be loaded.

For example:

if you are using zsh shell, need to add in ~/.zshrc file

if you are using bash shell, need to add in ~/.bashrc file

And then open a new tab to see the effect.

0
12

I think this more generic solution

echo 'source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
1
  • This should really be the answer.
    – volvox
    Mar 13, 2023 at 14:24
9

For me in Ubuntu(18.08), I have added below line in .bashrc and it works.

 source /home/username/.rvm/scripts/rvm

Please add this line.

2
  • 1
    Thanks! This worked for me on MacOS! As a suggestion, I think it's better to use ~ to refer to user's home path: source ~/.rvm/scripts/rvm :-) Nov 29, 2018 at 14:09
  • Thanks for posting this answer. Worked for me on Ubuntu 20.04.
    – John Cowan
    Dec 6, 2020 at 17:40
9

Following work for me in ubuntu 19.1

source ~/.rvm/scripts/rvm
2
  • 3
    This worked for me using WSL2 Ubuntu. Thanks 😊 May 5, 2021 at 5:13
  • 1
    @Sagar Jethi, you made my day.
    – Adnan
    Jun 13, 2022 at 14:28
3

From a new Ubuntu 16.04 Installation

1) Terminal => Edit => Profile Preferences

2) Command Tab => Check Run command as a login shell

3) Close, and reopen terminal

rvm --default use 2.2.4
1

If RVM was installed with dedicated ubuntu RVM installer https://github.com/rvm/ubuntu_rvm the path to RVM scripts will be different /usr/share/rvm/scripts/rvm. So to add it to your .bashrc run the following command:

echo 'source "/usr/share/rvm/scripts/rvm"' >> ~/.bashrc
0
0

FWIW- I just ran across this as well, it was in the context of a cancelled selenium run. Perhaps there was a sub-shell being instantiated and left in place. Closing that terminal window and opening a new one was all I needed to do. (macOS Sierra)

0
     Usually this is caused by shell initialization files. Search for PATH=... entries.
     You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
     To fix it temporarily in this shell session run: rvm use ruby-2.6.5
     To ignore this error add "rvm_silence_path_mismatch_check_flag=1" to your "~/.rvmrc" file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.