241

I just installed RVM, but can't make it work. I have such line at the end of my .profile file:

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

I tried to run source .profile and restarting terminal, but still, when I run rvm use 1.9.2 I'm getting:

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

My system is Ubuntu 11.10.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
amorfis
  • 15,390
  • 15
  • 77
  • 125

22 Answers22

453

You need to run the following

$ source ~/.rvm/scripts/rvm

then run this

$ type rvm | head -n 1

and if you get

rvm is a function

the problem is solved.

You also need to run user$ rvm requirements to see dependency requirements for your operating system

Source: https://rvm.io/rvm/install/

I forget mention that you need to put this code into you ~/.bashrc or ~/.zshrc file and you will not need to write this code again.

starball
  • 20,030
  • 7
  • 43
  • 238
Jorge García
  • 5,113
  • 2
  • 14
  • 17
  • 2
    Thanks. Worked for me on ubuntu 10.04. – vekozlov Sep 05 '12 at 18:08
  • 20
    This solution only works in the current shell session. If you follow this solution you will have to repeat these steps every time you log on to the console again. A more permanent solution is to add the following to the ~/.bashrc file: if test -f ~/.rvm/scripts/rvm; then [ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm fi – Stanley Sep 17 '12 at 05:58
  • This really should be on RVM's gnome integration page, much more concise and worked like a charm on mint nadia running KDE & Cinammon nonetheless – k4t434sis Feb 19 '13 at 01:52
  • 1
    And what if it still isn't a function after you do all this? – Br.Bill Apr 19 '13 at 01:38
  • If @Stanley's solution doesn't work, also do this: http://stackoverflow.com/questions/820517/bashrc-at-ssh-login – Adam Grant Jun 13 '13 at 14:43
  • i used this to update from ruby 1.9.3 to 2.0.0 is that the right way? I was getting the 'rvm is not a function error' – Connor Leech Oct 30 '13 at 13:03
  • @ConnorLeech did you use another terminal session? – Jorge García Nov 15 '13 at 19:52
  • Save my day, better than any online rvm help I've seen so far, including https://rvm.io/rvm/basics, which is lengthy and helpless. – user180574 Sep 02 '16 at 15:47
  • Why not just run `/bin/bash --login`? Does that not work? Or you just don't want to type that up every time? – kimbaudi Dec 16 '16 at 09:00
  • @stanley's solution - I get ".bashrc: line 15: syntax error: unexpected end of file". But if I put a semicolon before 'fi' it runs without error. Unfortunately, rvm is still "not a function" afterwords. – JosephK Feb 14 '17 at 04:40
  • Didn't worked for me even on hitting 'type rvm | head -n 1' after getting the message rvm is function .when trying to hit 'rvm use ..' – Jaswinder Mar 05 '17 at 08:36
  • This helps if you try to run rvm commands on VSCode terminal connected to WSL Ubuntu – eduardo a Jun 10 '21 at 18:10
245

You are not using an login shell.

The process of enabling the login flag is described here, also some details on what a login shell is can be found here.

Thus, you need to check the option "Run as login shell" in the Gnome terminal's settings. It is required to open new terminal after this setting the flag.

Sometimes it is required to set the command to /bin/bash --login.


For remote connections it is important to understand the differene between running interactive ssh session and executing single commands.

While running ssh server and then working with the server interactively you are using login shell by default and it's all fine, but for ssh server "command" you are not using login shell and it would be required to run it with ssh server 'bash -lc "command"'.

Any remote invocation can have the same problem as executing single command with ssh.

mpapis
  • 52,729
  • 14
  • 121
  • 158
  • 4
    What would the equivalent solution be on mac? – Adam Grant May 08 '12 at 16:39
  • 8
    try `rvm get stable --auto` and check your terminal settings – mpapis Jun 15 '12 at 16:41
  • 10
    fyi: we had to start a new terminal after setting this. – oma Sep 12 '12 at 17:09
  • 2
    @mpapis How would I setup gnome-terminal to "Run command as login shell" on a remote server for which I can't forward X server to my machine? – Waseem May 03 '13 at 06:05
  • 12
    To follow @mpapis's suggestion, `--auto` had been deprecated in favour of `--auto-dotfiles` so the command now is `rvm get stable --auto-dotfiles` – Mart Van de Ven Nov 08 '13 at 03:56
  • If any one knows how to change this setting in Lubuntu, help would be appreciated. Wash't sure if it would be appropriate here, so I posted it to [Ask Ubuntu](http://askubuntu.com/questions/524640/run-command-as-login-shell-in-lxterminal). – Roman Davis Sep 16 '14 at 10:17
  • Any reason why the scripts are sourced in `*profile` files instead of `*rc` files? – balki Nov 01 '15 at 21:37
  • 1
    I'm not sure how my shell logged out, but anyway **close your terminal and open it again**, that worked for me. – Mirror318 Jun 09 '16 at 21:34
  • If you are using zsh, you can add `[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*` to your .zshrc file. Source it and try again, it'll work. Specially useful if you use zsh on your deployment servers. – Vishnu Narang Mar 13 '17 at 18:33
  • @VishnuNarang your solution is not using login shell, as I mentioned in the answer it's important to use login shell. – mpapis Mar 16 '17 at 11:21
  • @mpapis, but, why is it important to use a login shell?. I can't find anywhere the motivation for this. – Jaime Hablutzel Apr 17 '20 at 17:05
108

To permanently resolve this just cut/paste following line:

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

From: ~/.bash_profile file

To: ~/.bashrc file

Reason this works is that .bashrc is executed each time you enter the terminal, and .bash_profile each time you login. That is why solution /bin/bash --login works, but you have to do that each time you enter the terminal. This way you are set until your next format, and you will forget all this by than :)

Haris Krajina
  • 14,824
  • 12
  • 64
  • 81
  • As a screen user, I always need to put this line in `~/.bashrc` instead of `~/.bash_profile`. – ryenus May 11 '14 at 04:27
  • 2
    Thanks! I was extremely bothered by the two second delay necessary for gnome to login. This will prevent that delay. – justinpage May 31 '14 at 22:08
  • 7
    Why doesn't the rvm installation do this automatically? – balki Nov 01 '15 at 21:39
  • @mpapis is the release manager for rvm and he says doing it this way "can fail X sessions (Fedora 17 if I recall correctly), it fails rsync sessions ... and more reasons I can not recall right now". I think I'm going to just stick with `/bin/bash --login. – kimbaudi Dec 16 '16 at 09:04
30

I too faced this problem. Finally i executed this line on terminal.

source ~/.rvm/scripts/rvm

Problem is fixed. Because this line will make the RVM instance a function for a particular time.

Bastin Robin
  • 907
  • 16
  • 30
  • 2
    Simplest answer of all. just put that line into your ~/.bashrc and you're good to go with any terminal emulator. – Nikkolasg Aug 21 '15 at 10:36
  • 1
    Hi - although this command 'fixed' things for the term session I was in, the results weren't _sticky_ and didn't help new (or other) term sessions. And it seems the desktop is also ignorant of the changes. I'm "anti-" the login thing too because it is per session/login based. Personally I want the ability to compare same program with different Ruby-s and versions. – will Oct 07 '15 at 11:50
  • 1
    You're the real mvp. Nothing else worked until I tried this. I don't care if it's temporary I just needed a fix. – ian-campbell Oct 22 '15 at 16:48
  • Where is the install file for rvm, so when you install it, it takes care of this and other issues? I used the process described on their home page, and have spent hours trying to get it to "just work". Should be something like "yum install rvm" and everything is done and ready to go. – JosephK Feb 06 '17 at 05:49
21

The latest RVM (rvm 1.11.6 (stable)) stopped working on Ubuntu (10.10 - 64 bit - nerdy gnat or whatever) - I kept getting

"RVM is not a function, selecting rubies with 'rvm use ...' will not work."

Before, I got the message, but 'rvm 1.9.3-p0@rails321' would work. Now, it wouldn't work - you couldn't change gemsets at all.

Nothing worked, until I found this - make this the LAST line in /home/your-name/.bashrc

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

Haris Krajina
  • 14,824
  • 12
  • 64
  • 81
Rod McLaughlin
  • 219
  • 1
  • 2
  • 2
    "rvm get stable --auto" added to .bash_login [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" and removed it from .bashrc - I added source ~/.bash_login at the end of .bashrc and at the BEGINNING of any script which changes gemsets in midstream – Rod McLaughlin Apr 05 '12 at 17:26
10

As you said, the error shown could be the following one.

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.

As said above, just type '/bin/bash --login' in your terminal (after restarting your terminal), then type the comand 'rvm use 1.9.3' (for e.g.) and it will start using the same version.

Just execute the command 'ruby -v' to confirm that the RVM is using the updated version of Ruby.

Rajesh Omanakuttan
  • 6,788
  • 7
  • 47
  • 85
9

I had this problem too on a fresh rvm installation, and non of the answers here fixed it. Going into the official rvm site, on the basics section, they have this command:

# from http://rvm.io/rvm/basics

source $(rvm 1.9.3 do rvm env --path)

You should change 1.9.3 for the ruby version that you actually want, and it'll make rvm a function regardless of the shell type.

vcanales
  • 1,818
  • 16
  • 20
7

Maybe you can try belows:

  • Your Terminal ->
  • Edit ->
  • Profile Preferences ->
  • Title and Command ->
  • Check the "Run command as a login shell"
  • Done
Feuda
  • 2,335
  • 30
  • 28
  • This is the easiest solution and the correct one, as a normal shell skips .profile, using this option will cause it to load and not need to edit .bashrc at all. – DWils Apr 05 '14 at 20:56
7

Run bash --login and then run rvm use 2.0.0.

Snykri
  • 580
  • 1
  • 9
  • 15
Gowri Tumma
  • 101
  • 1
  • 2
7

even though you accepted an answer, i'd like to suggest another way .. ~/.bashrc is loaded before any shell is opened. Add that line at the end of that, and you don't need any of that login shell thing

kapv89
  • 1,692
  • 1
  • 17
  • 20
  • "that login shell thing" is there for a reason, I have did many tests with RVM sourcing and it's the only way that guarantees work without undetectable and hard to solve errors – mpapis Mar 30 '12 at 07:54
  • @mpapis Can you explain the reason? From other answers, looks like most are fine with moving the line to rc file – balki Nov 01 '15 at 21:42
  • for example it can fail X sessions (Fedora 17 if I recall correctly), it fails rsync sessions ... and more reasons I can not recall right now – mpapis Nov 20 '15 at 22:16
4

Open Up the Terminal and then Go to Edit > Profile Preferences and then go to the Tab "Title and Command" and Check "Run Command as Login Shell".

Boot Up a Bash and Now you can install Gems directly from the terminal without the use of sudo and the error "RVM is not a function, selecting rubies with 'rvm use ...' will not work." will be eliminated.

Cheers.

ajknzhol
  • 6,322
  • 13
  • 45
  • 72
4

All the above answers are valid. But when i faced the same issue, the solution was the following:

  • Update ZSH. (Tried to update directly din't work for some reason. So uninstalled and reinstalled updated version from here)
  • Set default shell as zsh (i.e. if you prefer zsh) using sudo chsh -s $(which zsh) $USER
  • Ensure that the following code is at the bottom of your .zshrc after you have installed the latest RVM probably using CURL from official RVM site

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
    source ~/.profile
    
  • MOST IMPORTANT POINT: Ensure that in your .zshrc file every export to PATH is appended with :$PATH. Which i believe was the root of my problems even after following the above steps.

  • post this all my problems of RVM Not being a function went away. If it still does not work, give some error trace over here. After a few hours of struggle to solve this issue, i'm sure i must have seen all related errors.

Hope it helps. Cheers!

Vishnu Narang
  • 605
  • 8
  • 15
  • yes sir. That worked for me. Didnt understand the MOST IMPORTANT POINT part but, It worked. – Ricbermo Jan 12 '14 at 15:40
  • When you try to install RVM, it'll give a warning if you have `export PATH="/usr/bin:"`. It'll ask you to append `$PATH` to it. This was a cause of one of my problems. Hence, every `export PATH` should have `$PATH` appended so that before the export, whatever the `PATH` variable had gets appended. Anyways, good that this was helpful. – Vishnu Narang Jan 15 '14 at 08:56
3

Procedure for installing Ruby 1.9.3-p125 on Mac OSX 10.8 Mountain Lion

  1. You've already installed the latest XCode (>= 4.3) and and the command line Objective-C compiler "clang".
  2. You must run the "bash" shell for this procedure to work.
  3. Go to System Preferences
  4. Click on "Users & Groups"
  5. Click the lock on the bottom left of the panel and enter your password to unlock it.
  6. "Ctrl-Click" on your user icon in the left pane of the panel and choose "Advanced Options..."
  7. Change the Login Shell to "/bin/bash"
  8. Close the preferences
  9. Open a terminal window (press command+spacebar and type in "terminal")
  10. Follow the instructions at:

http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/

Notes:

  • To install ruby, you may need to specify the clang compiler:

    $ rvm install 1.9.3p125 --with-gcc=clang

  • If RVM gripes about /usr/local/rvm not found, you need to create a link:

    $ ln -s /Users/[your user name]/.rvm /usr/local/rvm

George Campbell
  • 568
  • 5
  • 10
  • I think they are up to P194 now. If you do rvm install 1.9.3 --with-gcc=clang, you will get the latest version of 1.9.3 automatically. – George Campbell Aug 18 '12 at 18:25
2
source ~/.bash_profile

... should do the trick ..., probably need to logout and login again.

How to reload .bash_profile from the command line?

Community
  • 1
  • 1
1

« Official » instructions are there: https://rvm.io/integration/gnome-terminal/

Sidhannowe
  • 465
  • 5
  • 11
1

I fixed it by adding this line to .bash_profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
AlekseiPetrovski
  • 1,016
  • 9
  • 17
1

I'd got the same error because I'd ever installed the old rvm version ruby-rvm with the apt-get command.

I solved the problem by remove the script line to config the old rvm in .bashrc file.

Check the old rvm config script and then run source .profile

ryancheung
  • 2,999
  • 3
  • 24
  • 25
0

I had the same error, but none of the solutions on this page seemed to work. For me it was enough to add the rvm executable to my path:

PATH=$PATH:/usr/local/rvm/bin/

Et voila!

Rafael Bugajewski
  • 1,702
  • 3
  • 22
  • 37
0

I had the same issue and I did this in my .bash_profile and it worked. source "$HOME/.rvm/scripts/rvm".

Sadiksha Gautam
  • 5,032
  • 6
  • 40
  • 71
0

For those who comes with same issue and they are using lubuntu like me I followed this link :

You start your terminal with

lxterminal -e "bash -il"

Thank to @mpapsis who pointed me to the right direction

nizzin
  • 31
  • 4
0

My unclean way to change of ruby version is

rvm alias create default ruby-2.2.3 && source ~/.bashrc && rvm list

it works because I have the line bellow in my ~/.bashrc but strangely it don't do the job automatically.

[[ -s "/usr/local/rvm/bin/rvm" ]] && source "/usr/local/rvm/bin/rvm"

I tried to connect with --login to my docker container

docker run -it imagename `/bin/bash --login`

but in this case the container stay open in background and I can't enter commands.

I tried both zhc and terminal with the option "open with /bin/bash --login"

bormat
  • 1,309
  • 12
  • 16
0

$ source ~/.rvm/scripts/rvm

if you don't want to do it again and again for every terminal tab enable the login shell by following these steps.

  1. got to preferences enter image description here

  2. enable run command as a login shell enter image description here

Cristik
  • 30,989
  • 25
  • 91
  • 127