OS X lion rvm, ruby install successfully, but doesn't execute. What am I missing? - ruby

Okie dokie - IT recently updated my system to lion, fresh install.
I followed the instructions at Federico Araujo's blog to prep for my install (http://www.frederico-araujo.com/2011/07/30/installing-rails-on-os-x-lion-with-homebrew-rvm-and-mysql/), with the exception that I used
curl -L get.rvm.io | bash -s stable --rails
from http://beginrescueend.com/rvm/install/ to handle the rvm/rubygems/rails install. No errors reported.
I've added
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM function
to my .profile, closed all windows, reopened terminal and ensured that .profile was sourced on launching terminal.
But no matter what I do, I am unable to use RVM to switch into 1.9.3 and use rails.
Nothing in path or $HOME/.rvm/scripts/rvm added to path:
$ rvm list
-sh: rvm: command not found
and
$ type rvm | head -1
-sh: type: rvm: not found
If I add $HOME/.rvm/bin to path, I can see the RVM jazz, but
$ type rvm | head -1
rvm is hashed (/Users/soychicka/.rvm/bin/rvm)
And if I add $HOME/.rvm/scripts to path, and
$ type rvm | head -1
rvm is /Users/soychicka/.rvm/scripts/rvm
And in the last case, issuing 'rvm list' doesn't throw an error, but simply returns a new prompt.
Again, it appears that everything compiled and installed properly; just can't get RVM to jf Ruby 1.9.3 and assorted gems into use.
What is wrong here? I've looked through all apparently relevant questions, but haven't een anything that appears to match...
This does not bode well for my attempts to open my team's eyes to the ease of prototyping with Rails...
UPDATE:
Adding the following to my .profile (but not .bash_profile) appears to have resolved the issue:
PATH=$HOME/.rvm/bin:$PATH
if [ -s "$HOME/.rvmrc" ]; then
source "$HOME/.rvmrc"
fi # to have $rvm_path defined if set
if [ -s "${rvm_path-$HOME/.rvm}/scripts/rvm" ]; then
source "${rvm_path-$HOME/.rvm}/scripts/rvm"
fi
But to me, it feels a bit too hacky to be comfortable, and it still isn't clear why this differs from my other lion installs... First install was in February, but attempts to set up rvm on systems last month and this following the same set of instructions failed. Anybody have ideas?

From man bash
After reading that file, it looks for ~/.bash_profile,
~/.bash_login, and ~/.profile, in that order, and reads and
executes commands from the first one that exists and is readable.
Are you sure none of the other files exist?
Also execute
source "$HOME/.rvm/scripts/rvm"
in your shell and see if it works as expected.
I hope you're aware of the security implications of piping curl output directly into bash.

Adding the following to my .profile (but not .bash_profile) appears to have resolved the issue:
PATH=$HOME/.rvm/bin:$PATH
if [ -s "$HOME/.rvmrc" ]; then
source "$HOME/.rvmrc"
fi # to have $rvm_path defined if set
if [ -s "${rvm_path-$HOME/.rvm}/scripts/rvm" ]; then
source "${rvm_path-$HOME/.rvm}/scripts/rvm"
fi

Related

Need to Fix PATH in my bashrc File for RVM

I did a clean install of my operating system recently and copied my old .bashrc file from a backup. I installed rvm version 1.26.10 (latest stable version). I installed ruby 2.2.0. When I source the .bashrc file I get the following error:
Warning! PATH is not properly set up, '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.0#mygemset'.
Here are my PATH statements. The first line I included here is one that was in the new install of RVM in the .bash_profile file. I copied them into .bashrc. I'm also running postgres.app which requires the last statement in order to set it as the current PostgreSQL instance.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
export PATH="$PATH:$HOME/.rvm/bin"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I started with the .bashrc file recommended by the Ruby on Rails Tutorial by Michael Hartl (the version current in 2011 or 2012) and the settings used by RVM back then. I know things have changed a bit since then.
My bash knowledge is limited so any help would be appreciated.
UPDATE: 2/2/2015 2:40 pm CST
I changed my bash statements to the following and got rid of the warning:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
UPDATE: 2/2/2015 5:14 pm CST
Here are my Bash statements:
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql"
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Here is the output for echo $PATH:
/Users/username/.rvm/gems/ruby-2.2.0#gemsetname/bin:/Users/username/.rvm/gems/ruby-2.2.0#global/bin:/Users/username/.rvm/rubies/ruby-2.2.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/Users/username/.rvm/bin:/Users/username:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/Users/username/.rvm/bin
My RVM wouldn't stop complaining about PATH even though the last thing in my .bashrc was this line:
# RVM
source ~/.rvm/scripts/rvm
So I just redirected the complaining to /dev/null:
# RVM
source ~/.rvm/scripts/rvm > /dev/null 2>&1
rvm use default > /dev/null 2>&1
The last line also makes sure RVM is first in PATH, so it doesn't really have anything to complain about.
rvm expects its $PATH stuff to come first in $PATH. You should add items to the $PATH before sourcing rvm, not after.
After dealing with this for several days I decided to go ahead and continue to proceed with my implementation of postgres.app with the warning message I got with RVM. I ran my original bash statements in a different order.
export PATH="$PATH:$HOME/.rvm/bin"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I was successful in implementing postgres.app. I still get the warning message but my Ruby on Rails applications are able to find the correct gems and run successfully.
You should add the line like this
export PATH= '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin:other"
Maybe that can help you

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

rvm on OS 10.9 a few problems: second export path to .bash_profile, missing 2.0 path, and missing files

1)
I have this error every time I load a new bash terminal
-bash: /etc/profile.d/sm.sh: No such file or directory
-bash: /etc/profile.d/rvm.sh: No such file or directory
I saw this previously asked question with the answer to simply delete the references from .bashrc. But the answer is unaccepted and unvoted and the references to these files are not in .bashrc but in ~/etc/profile
I should note that I don't have a profile.d directory under /etc. I have files profile and profile~orig
2)
RVM added a second export path after I ran rvm get stable, but did not include a reference to Ruby 2.0.0 in either.
.bash_profile
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=/usr/local/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/mcb/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
My instinct is to combine them into one, eliminate repeats, and add the references to ruby 2 manually. I also added the $PATH: myself, since that didn't work the first time either.
3)
This is clearly not right
my-macbook-pro:~ mcb$ rvm get sable --auto-dotfiles
Warning! PATH is not properly set up, '/Users/mcb/.rvm/gems/ruby-2.0.0-p247/bin' is not available,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p247'.
cat: /Users/mcb/.rvm/help/get: No such file or directory
So, long story short I'm starting to get worried about trying to fix anything else myself without some sort of guidance for fear of just making things worse.
for 1) check /etc/profile for those two files references
for 2) remove export PATH=/usr/local/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448/bin:/Users/mcb/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/mcb/.rvm/rubies/ruby-1.9.3-p448/bin:... from ~/.bash_profile
for 3) rvm get sable => rvm get stable
I think the problem is that you are adding ruby 1.9.3 explicitly in your PATH, and that's a job that rvm shoud do.
In my case I have no direct reference to any of the ruby installations in my PATH.
Try cleaning your path from anything ruby and rvm related, and let rvm load as a function.
This is the .bash_profile on my computer (with rvm and brew working):
export PATH=/usr/local/bin:/usr/local/sbin:$PATH:/usr/local/opt/ruby/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
To check if rvm is correctly configured you can run:
type rvm | head -n 1
The result should be: "rvm is a function"
Checkout rvm official webpage for more details on how it works: https://rvm.io/rvm/install

"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

How to use "RVM --default" on MacOSX

After using Ruby and Rails for quite some time now, I wanted to try RVM. Everything works fine, except for one thing:
In a freshly opened Terminal ruby points to the system's ruby, despite the fact, that I used the rvm --default command.
user#terra ~ $ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
user#terra ~ $ which ruby
/opt/local/bin/ruby
user#terra ~ $ rvm list
ruby-1.8.7-p334 [ ]
=> ruby-1.9.2-p180 [ ]
Everything is fine after I call rvm reload
user#terra ~ $ rvm reload
user#terra ~ $ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.1]
tmangner#terra ~ $ which ruby
/Users/user/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
I set up my .bash_profile as described in the documentation:
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
That --default does not seem to work for me ...
user#terra ~ $ rvm use 1.9.2 --default
Using /Users/user/.rvm/gems/ruby-1.9.2-p180
user#terra ~ $ rvm default
user#terra ~ $
I'm using Mac OS X Snow Leopard (10.6.6)
I had the same problem once. It turned out the rvm-script got loaded twice, which broke things a bit.
Check all the files that load when you open a shell:
/etc/profile
~/.bashrc
~/.bash_profile
and so on, and make sure they don't load RVM twice.
Maybe put
echo "Going to load RVM"
before
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
in your ~/.bash_profile to see if it happens or not.
Moving the initialization
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
in the bottom of ~/.bash_profile solved the problem for me.
A possible fix for ZSH users:
Somehow I had:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
in both .zprofile and .zshrc.
Removing the line from .zprofile resolved the issue. (Though you should be able to remove from either, as long as it appears just once)
I had the same problem.
Moving:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
after the line from MacPorts:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
solved the problem for me.
Run the command:
rvm use --default 1.9.2?
This worked for me on openSUSE, I don't know about Snow Leopard though.
Instead of:
rvm use 1.9.2 --default
I used the full version:
rvm use ruby-1.9.2-p290 --default
That worked for me in zsh.
I had the same problem and since I use Oh-My-Zsh it was a little bit more difficult to track if I have duplicate calls to RVM.
I fixed it by moving the call to RVM from the separate rvm.zsh file located in my \custom folder inside \oh-my-zsh to the very end of my main .zshrc file.
It looks like RVM is really sensitive to being called not at the end of your zsh initialization sequence.
As a sanity check, make sure that the project you are working on has the same Ruby version that you try to set as default in the .ruby-version file.
It happened to me, and I couldn't figure out why rvm doesn't use my default.
I had the same issue on Mac OS X 10.7, and later I found that my account was not added to the "rvm" group.
After I added myself to it I can set --default.
My issue was resolved by changing
PATH=/usr/local/bin
to
PATH=$PATH:/usr/local/bin
in my .zshrc file.
Obviously, you need to make sure RVM is properly installed first, and run the type rvm | head -1 check that #choise suggested. rvm use --default 1.9.3-p362 now works properly.
See "Sometimes, CD to a dir with .rvmrc doesn't set the Ruby version or gemset" for more information.
Try this to set default Ruby for a new shell:
sudo rvm alias create default 1.9.2
For some really newbies on Mac OS use JewelryBox and in preferences section you find
"show default ruby in system menu bar"
checking this allow you to switch between rubies.
You can select your pre-installed rubygems (if you have rubygems) via "system#*" choice.
I followed the suggestions above - checked my bash_profile (which was fine) and also noticed that in ubuntu you may need to head the advice of https://rvm.io/support/faq/#shell_login
However I was still having this problem until I realised that the project I was trying to run had a .rvmrc file that was specifying a version of ruby that I didn't have installed. When I corrected this - I stopped having the problem (so in fact it wasn't that the use default wasn't working, but that this project was overriding it)
I had to remove the [[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" line from ~/.bash_profile and had to move it to the very bottom of ~/.bashrc.
This fixed the issue on OS X 10.10.1.
What does type rvm | head -1 print out?
In my .bash_profile on the latest MacOS X I had to put:
# Ruby Version Manager
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
I also created a gemset and set this as default:
rvm reload
rvm install 1.9.2
rvm --create use 1.9.2#default
rvm --default use 1.9.2#default
You need to put the path to RVM in front of your PATH:
$ export PATH=/path/to/rvm-dir:$PATH
For some reason I had in my $HOME/bin directory ruby, gem, rake, ... file stubs. Therefore my rvm --default use 1.9.3 didn't work as expected. Removing the $HOME/bin directory solved the problem.
cat bin/ruby
#!/usr/bin/env bash
if [[ -s "/usr/local/rvm/environments/ruby-1.9.2-p290" ]]
then
source "/usr/local/rvm/environments/ruby-1.9.2-p290"
exec ruby "$#"
else
echo "ERROR: Missing RVM environment file: '/usr/local/rvm/environments/ruby-1.9.2-p290'" >&2
exit 1
fi

Resources