rvm installation not working: "RVM is not a function" - ruby

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.

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.

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.

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

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.

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"

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.

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.

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

Maybe you can try belows:
Your Terminal ->
Edit ->
Profile Preferences ->
Title and Command ->
Check the "Run command as a login shell"
Done

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

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.

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!

Procedure for installing Ruby 1.9.3-p125 on Mac OSX 10.8 Mountain Lion
You've already installed the latest XCode (>= 4.3) and and the command line Objective-C
compiler "clang".
You must run the "bash" shell for this procedure to work.
Go to System Preferences
Click on "Users & Groups"
Click the lock on the bottom left of the panel and enter your password to unlock it.
"Ctrl-Click" on your user icon in the left pane of the panel and choose "Advanced Options..."
Change the Login Shell to "/bin/bash"
Close the preferences
Open a terminal window (press command+spacebar and type in "terminal")
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

source ~/.bash_profile
... should do the trick ..., probably need to logout and login again.
How to reload .bash_profile from the command line?

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

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

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*

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!

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

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

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"

$ 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.
got to preferences
enter image description here
enable run command as a login shell
enter image description here

Related

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

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.
Your console is not running as a login shell and hence have no access to rvm function. If you are running Ubuntu, you can:
Open console
Select Edit -> Profile Preferences
Select tab: Title and Command
Check box 'Run command as a login shell'
Restart terminal
Type bash --login from your terminal. And then give rvm use 2.0.0
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
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
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
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.
Same principle as other answers, just thought it was quicker than re-opening terminals :)
bash -l -c "rvm use 2.0.0"
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.
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.
I think this more generic solution
echo 'source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Following work for me in ubuntu 19.1
source ~/.rvm/scripts/rvm
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
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
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)
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.

RVM Ruby installation not successful

I'm trying to install ruby using rvm on linux debian. This is my problem:
Ruby didn't work at all in the terminal (that is, it said: ruby:command not found.
Then I followed this thread RVM ruby installation issue and it worked. However, after I closed that terminal and opened a new one, it didn't work anymore.
Do I have to change something in the autostarts? Can someone please help me!!
Check if your ~/.profile file contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
and your .bash_profile file contains:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if it have it and still don't work add this line to your ~/.bash_profile
source ~/.profile
I'm assuming you are using bash as your shell. You may want to check it in your user preferences (depend on your distro).
I assume the installation worked, what did not worked is you missed to use the installed ruby:
rvm use ruby-2.1.0
in your case it would print you a warning about not using login-shell - follow the instructions, they ae there to help you

Ruby installation and profile reload

I've recently installed ruby using this tutorial :
http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
However every time I turn off my computer and open terminal. I need to type . ~/.bash_profile so I can do bundle install or anything else ruby related.
I'm using ubuntu 12.04, has anyone encountered similar issue?
In addition to what McGar said, you want to make sure that you have 'Run command as a login shell" checked in your terminal window.
For instance, in Fedora 19 (I'm sure it'd be the same in Ubuntu 12.04) go to: Edit -> Profile Preferences -> Title and Command, and then check 'Run command as login shell'. I'd also recommend close/open all open terminals after making that change.
Do you have something like following lines in your .bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
#This loads rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
check this tutorial of enabling login shell => http://rvm.io/integration/gnome-terminal (not copy pasting as instruction on the site might get updated / improved).

RVM and Jenkins setup

I am new to Jenkins CI. I'm install RVM in my remote Jenkins and when I execute below shell.
#!/bin/bash -x
source ~/.bashrc
rvm use 1.9.3#rails-3.2.3
I get following errors.
+ source /var/lib/jenkins/.bashrc
++ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/var/lib/jenkins/.rvm/bin:/var/lib/jenkins/.rvm/bin
+ rvm use 1.9.3#rails-3.2.3
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal settings to allow shell login.
Please visit https://rvm.io/workflow/screen/ for example.
What does it mean? I don't have any idea. Please help me.
UPDATED: I'm tried below script but I still get errors:
#!/bin/bash -x
source /home/zeck/.bashrc
[[ -s ".rvmrc" ]] && source .rvmrc
export RAILS_ENV=test
bundle install
Errors:
/tmp/hudson457106939700368111.sh: line 5: bundle: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Jenkins build shell can't detect RVM, gemsets and gems. What should I do?
UPDATED 2: Therefore jenkins can't detect ruby.
+ ruby -v
/tmp/hudson2505951775163045158.sh: line 5: ruby: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILUR
I'm not using any jenkins plugn and I'm just run script from Build->Execute shell section.
As the error message suggests, RVM expects an login shell. Changing the hashbang line to #!/bin/bash -xl should resolve this.
try:
. $(/home/RVM_USER/.rvm/bin/rvm env 1.9.3#rails-3.2.3 --path)
make sure you run the stable RVM:
rvm get stable
NOTE:
Last Jenkins version does not always accept "source", but ".".
RVM_USER is the user that installed RVM.
Alternatively you can also export the RVM command in the main PATH.
Yes, apparently you miss the $HOME/.rvm/bin in your PATH. I am using rvm successfully from Hudson on Mac OS X. First thing to notice is that, unless you define BASH_ENV environment variable (ENV for sh), .bashrc is called automatically only with interactive non-login shell. Such a shell is started when you do - for example - the following from the command line:
$ /bin/bash
When you use #!/bin/bash in your script, .bashrc will not be called.
To make rvm work with Hudson, I have the following in my .bash_profile:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Thanks to [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" I have rvm enabled every time I start new terminal window (interactive, login shell).
I do not put anything in my .bashrc, especially I am not sourcing rvm scripts there. Nothing wrong with that, but if any other scripts makes something stupid like setting `export BASH_ENV=$HOME/.bashrc' and then invoke non-interactive shell, you see what may happen - it is actually easy to forget.
Therefore, instead of loading things to your .bashrc, it is better to keep your script independent from any shell startup file and make sure that the correct environment is set up within the script. I still keep $HOME/.rvm/bin in my .bash_profile, but then I include the following at the beginning of my script:
#!/bin/bash
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
rvm use 1.9.3-head#MyGemSet
set -ex
cucumber # just an example
Notice the -e option which forces the script to exit with error code if any command following set -ex fails. This is behavior you may want when using the script with Hudson.
It is incorrect to say that RVM expects a login shell. Although using #!/bin/bash -l in your script will work, it does not seem like the best approach.
Just add this code in your shell script, i think rvm is loading from your source so it should work else need to export PATH variable
#!/bin/bash -l
source ~/.bashrc
rvm use 1.9.3#rails-3.2.3
l is for login shel, if you include x then it would be for debugging too.
adding a shebang to the build commands in jenkins fixed this for me
#!/usr/bin/env bash
rvm use 2.0.0
bundle install
rake test
...
Jenkins nodes don't load paths the same way, so it's not using the proper path to find rvm's version of ruby. You can set the path for a given agent.
Find your current PATH by doing echo $PATH
Assuming you've set up rvm properly, find where rvm's version of ruby is located by running which ruby
There's a setting in the Configuration of your agent where you can set environmental variables. Set PATH to be 1 and 2 concatenated.

"RVM is not a function" error

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.
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:
Configure your terminal emulator to start a login shell, rather than a non-login shell, so that your .profile is loaded.
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!
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:
rvm get stable --auto-dotfiles as outlined in the RVM documentation here
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

Resources