RVM,Gemset, Bash on MacOSX - what have I done during my upgrade? - ruby-on-rails

Every time I open a new terminal in Mac OSX Lion, rails isn't loaded. This is after I upgraded to ruby 1.9.3 and rails 3.2 - so I was doing a lot of configuring but not sure what I've screwed up. It used to work fine.
If I load a new terminal on startup, and type:
rvm
that works.
If I type
ruby -v
I get the correct (1.9.3)
but if I type rails -v, I get an error saying:
/Users/userishere/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find rails (>= 0) amongst [rake-0.9.2.2, rake-0.9.2] (Gem::LoadError)
from /Users/userishere/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/userishere/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems.rb:1208:in `gem'
from /usr/bin/rails:18:in `<main>'
If I type:
rvm use 1.9.3p0#rails32 --default
That makes rails work as normal, but only in that terminal window -even a new tab in terminal, rails gives errors - how do I get it to accept that gemset/config as the global default whenever I start up? I have:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
in my .bash_profile.
What have I done to my config / missed in my upgrade? It seems like something simple, but I'm not spotting it.

I just switched my own default rvm by using the command rvm 1.9.2-p290#mybranch --default (not that I didn't have 'use' in the command)
Then, if you open a new terminal window or tab and type rvm list you should see a => next to the ruby version it's using. I see this:
ree-1.8.7-2010.02 [ x86_64 ]
ruby-1.8.7-p302 [ x86_64 ]
ruby-1.9.1-p378 [ x86_64 ]
ruby-1.9.2-p0 [ x86_64 ]
ruby-1.9.2-p136 [ x86_64 ]
ruby-1.9.2-p180 [ x86_64 ]
=> ruby-1.9.2-p290 [ x86_64 ]
I like to see which rvm version and gemset I'm using next to my command prompt. In your .bash_profile right before the line you listed that loads the RVM function, add this:
PS1="\$(~/.rvm/bin/rvm-prompt i v g s) $PS1"
Which prepends this to my prompt: ruby-1.9.2#myapp

rvm 1.9.3-p0#rails32 --default only set it working for the current terminal window, once I added another or exited and came back it was back to not working.
I fixed this by adding a .rvmrc file to my app directory. It now loads the gemset & ruby version correctly.
As per:
http://seanbehan.com/mac-os-x/installing-and-using-rvm-on-mac-os-x-creating-gemsets-and-reverting-to-original-environment/

Related

Where is ruby stored on mac?

I am looking for a path of where ruby gets stored on mac?
I installed macruby on my mac and I am trying to see where it got installed. I want to include the path of macruby in my ruby script. When I do rvm list, I get:
=> macruby-0.12 [ i686 ]
* ruby-1.9.3-p545 [ x86_64 ]
ruby-2.1.1 [ x86_64 ]
ruby-2.1.2 [ x86_64 ]
ruby-2.1.2-version [ x86_64 ]
I use #!/usr/local/bin/macruby in my ruby script, but looks like macruby is not present in that location. When I execute "whereis ruby" command on I get back "/usr/bin/ruby", but when I execute "whereis ruby-1.9.3-p545" or "whereis macruby-0.12" I get nothing.
How do I find the path of where does all these ruby versions lie?
You can get the path to the local executable with
$ which ruby
the rvm rubies are in your rvm directory, which I believe is ~/.rvm/rubies (I use rbenv so not sure about the details)
The which command should pickup whatever shims/other magic RVM is using to set your shell ruby
You can find your answer by running one of the following commands:
which ruby
whereis ruby
type -P ruby

RVM troubleshooting

I am trying to fix my RVM. Last week everything was working fine but today for some reason my rails commands are not working. For example, if I try:
rails new blog
I get this error:
.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `require': cannot load such file -- rails/version (LoadError)
Is this because my ruby version is outdated? does anyone know how I could fix this? I looked all over and only found the rvm get stable command however that did not fix my issue. Thank you to anyone that knows what is going on here.
Sorry for the bad formatting, here you go.
here is ruby -v:
`
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
here is the error I get with rails -v:
/home/tyrel/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_e‌​xt/kernel_require.rb:110:in `require': cannot load such file -- rails/version (LoadError)
here is rvm list:
rvm rubies ruby-1.9.3-p448 [ x86_64 ] ruby-1.9.3-p484 [ x86_64 ] =* ruby-2.0.0-p247 [ x86_64 ] ruby-2.0.0-p353 [ x86_64 ] # => - current # =* - current && default # * - default
thanks for the help but upon further research I found what I needed to do.
First I ran:
gem pristine --all
Then I found another post on here that recommended trying this:
You need to run the follow
user$ source ~/.rvm/scripts/rvm
then run this
user$ 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. Cheers! -Jorge Garcia
After all that my RVM was fixed, and I can use my rails new projectname command.
Thanks for all the help community!!!<3

How can I change Ruby to version 1.9.3 (again) with RVM?

I used to work with Ruby version 1.9.3 on Ubuntu and made an update that probably screwed my bash profile and I need help to turn it back rather than using version 1.8.7. Right now rails s opens the server with Ruby 1.8.7 and I get errors because of the newer syntax I use in my app.
.bash_profile:
cat ~/.bash_profile
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
which rails:
/usr/local/bin/rails
which ruby:
/usr/bin/ruby
ruby -v:
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
rvm list:
rvm rubies
=* ruby-1.9.3-p194 [ i686 ]
# => - current
# =* - current && default
# * - default
rvm use 1.9.3:
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.
You are not in the login shell. To enter the login shell try this command:
/bin/bash --login
After that you will be able to use RVM to select Ruby.
Also, there is permanent way, that you won't have to write this line everytime you open your terminal.
Try this:
Edit menu -> Profile Preferences
A dialog will appear, now select Run command in login shell.
After that, whenever you open your terminal, you will enter into the login shell, and you will be able to use RVM.
There is another way, you can write /bin/bash --login in your .bash_profile which will load every time when you reboot.

Can't seem to "use" the RVM Ruby install

I'm getting this error when I try to invoke rails, rails -v or rails -c:
/usr/lib/ruby/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:214:in `activate'
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
I installed RVM, used it to install Ruby 1.9.3, and switched to it rvm use 1.9.3 --default.
When I ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
I also gem install rails --no-rdoc --no-ri and checked...ls ~/ruby/gems/gems/:
actionmailer-3.2.8/ journey-1.0.4/ rake-0.9.2.2/
actionpack-3.2.8/ json-1.7.5/ rdoc-3.12/
activemodel-3.2.8/ mail-2.4.4/ rubygems-bundler-1.0.7/
activerecord-3.2.8/ mime-types-1.19/ rvm-1.11.3.5/
activeresource-3.2.8/ multi_json-1.3.6/ sprockets-2.1.3/
activesupport-3.2.8/ polyglot-0.3.3/ sprockets-2.4.5/
arel-3.0.2/ rack-1.4.1/ thor-0.16.0/
builder-3.0.0/ rack-cache-1.2/ tilt-1.3.3/
bundler-1.1.5/ rack-ssl-1.3.2/ treetop-1.4.10/
erubis-2.7.0/ rack-test-0.6.1/ tzinfo-0.3.33/
hike-1.2.1/ rails-3.2.8/
i18n-0.6.0/ railties-3.2.8/
And if I echo $GEM_PATH:
/home/flackend/.rvm/gems/ruby-1.9.3-p194:/home/flackend/.rvm/gems/ruby-1.9.3-p194#global
echo $PATH:
/home/flackend/.rvm/gems/ruby-1.9.3-p194/bin:/home/flackend/.rvm/gems/ruby-1.9.3-p194#global/bin:/home/flackend/.rvm/rubies/ruby-1.9.3-p194/bin:/home/flackend/.rvm/bin:/usr/local/jdk/bin:/home/flackend/perl5/bin:/usr/kerberos/bin:/usr/lib/courier-imap/bin:/usr/lib64/ccache:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/home/flackend/.rvm/bin:/home/flackend/bin
cat ~/.bashrc:
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
cat ~/.bash_profile:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
So somewhere something has a path that says to look at the system Ruby install. Any ideas? Thanks!
EDIT
Okay, also, If i switch back to the system Ruby, rvm use system, and rails -v, I get:
Rails 2.3.8
So I have no idea at all what this error is indicating.
You have not completed rvm installation. You need add ~/.rvm bin paths before /usr/bin by command in .bashrc:
[[ -s "/Users/pftg/.rvm/scripts/rvm" ]] && source "/Users/pftg/.rvm/scripts/rvm".
To test just check $PATH env. Should be similar to:
/.../.rvm/gems/ruby-1.9.3-p125#global/bin:/.../.rvm/rubies/ruby-1.9.3-p125/bin:/.../.rvm/bin:/usr/local/bin
If you installed everything ruby as well as rails means, you may need to select the 'Run command as login shell' checkbox by doing following,
Open terminal
Go to Edit tab, then select Profile Preferences from the menu item.
The Profile Preferences window should be displayed, then select Title and Command tab.
Then select the checkbox Run command as a login shell.
I just used RVM to create a "gemset", switched to it, and tried installing Rails again and it works now.
https://rvm.io/gemsets/
I'm not sure why that fixed it or why it wasn't working before. I like when things work, but I would rather have figured out why it wasn't working with the #global gemset.
Thanks for all your help!
I had the exact symptoms described above as well and was stuck on this problem for quite some time (the ruby environment and dependencies are a horrible mess). I can't say I'm out of the woods yet but at least I'm picking up the correct version of rails now and gotten past this error.
I believe the real issue here is actually to do with zlib. It seems that it's a crucial component to separate your system version of ruby (v1.8 likely install via yum/apt-get) with the other versions or Ruby you need (installed via rvm) for other projects.
If you do not have zlib installed, or rvm is not using it correctly, then sometimes you will pick up the system ruby/rails and all sorts of strange errors occur.
If you DO have zlib installed (yum/apt-get install zlib) then the trick I discovered was that I specifically had to tell rvm which version of zlib to use when installing ruby.
rvm install 1.9.3 --with-zlib-dir=$rvm_path/usr

RVM: specify a ruby version to use

I know how to use RVM, but now I have a weird problem, which I do not understand why.
Here is the simple story (I am using Ubuntu):
I have created a Rails project, the direcotry of this project is "bookstore/".
I go to project directory by cd bookstore , and type command rvm list like following:
bookstore/$ rvm list
rvm rubies
ruby-1.9.2-p136 [ i386 ]
ruby-1.8.7-p352 [ i386 ]
ruby-1.8.7-p330 [ i386 ]
ruby-1.8.6-p420 [ i386 ]
ruby-1.9.2-p290 [ i386 ]
Since I did not see the => arrow sign which is supposed to indicate the current ruby version in use, so I specify the ruby version with the following RVM command:
bookstore/$ rvm use ruby-1.9.2-p290
Using /home/usr/.rvm/gems/ruby-1.9.2-p290
Now, if I rvm list I see my project is using ruby v1.9.2 :
bookstore/$ rvm list
rvm rubies
ruby-1.9.2-p136 [ i386 ]
ruby-1.8.7-p352 [ i386 ]
ruby-1.8.7-p330 [ i386 ]
ruby-1.8.6-p420 [ i386 ]
=> ruby-1.9.2-p290 [ i386 ]
Every thing works fine at this point!
But, if now I open a new terminal window on Ubuntu, and cd to the project directory, and run the command rvm list again, I got:
bookstore/$ rvm list
rvm rubies
ruby-1.9.2-p136 [ i386 ]
ruby-1.8.7-p352 [ i386 ]
ruby-1.8.7-p330 [ i386 ]
ruby-1.8.6-p420 [ i386 ]
ruby-1.9.2-p290 [ i386 ]
Where is the => to indicate the ruby version I specified previously? Why it again needs me to specify the ruby version?
It happens always when I open a new terminal window. How to have my project "remember" the ruby version I have specified?
Dave is right, you should set a default. But also, look into defining an .rvmrc file on a per-project or per-machine basis. I use project-specific rvmrc files, so I can use different rubies and gemsets for each project, and changing into the directory automatically switches to that project's ruby/gemset.
For example, my rvmrc for company site project:
brett#bender:~/Sites/bearded/bearded(master)$ cat .rvmrc
rvm 1.9.3#bearded
Edit: For explicitness' sake, to solve your problem using an rvmrc file, do the following (assuming you already installed the ruby version you want and created a gemset for this project's gems):
Create a file in bookstore/ directory named .rvmrc (in your favorite editor)
Add rvm ruby-1.9.2-p290 to the file and save it (you can use rvm ruby-1.9.2-p290#gemset_name if you have a gemset you want to default to)
Change directory out of your bookstore directory, then change back into it.
RVM should ask you if you want to trust this .rvmrc file (yes)
RVM should have automatically switched your active ruby and gemset to the ones specified in your rvmrc file for that project.
Also note that if your RVM is older than version 1.8.0 you will need to turn on rvmrc file support (versions 1.8.0+ have it turned on by default). The link at the top of my question contains instructions if you're so inclined.
You need to set the default.
rvm --default 1.9.2-p290 # Or whichever.
A new shell is a new environment; it will not (normally) inherit from already-opened terminals
For per-project settings, use a .rvmrc file in the root of your project, for example:
rvm --create gemset use 1.9.2-p0#my_project
The --create will create the gemset if it does not already exist, handy if you or others work on the same project across machines.

Resources