Problems getting Rails running on Mac OSX Snow Leopard - ruby-on-rails

Update and Solution
I finally got everything working after
1. Uninstalling everything ruby-related in /usr/local/... as well as uninstalling all versions of rails.
2. Installing RVM as a standard user -> i.e. installed in my home directory and NOT in /usr/local as root
3. rvm install 1.8.7 and set as default
Now everything seems to be working fine.
My conclusion after days of googling and reading about others' solutions is that Snow Leopard just doesn't handle the rails dev environment well unless you sandbox it through RVM in a local director. I resisted going to RVM because I don't have a need to manage multiple ruby versions.
Some of the responses below along with my code excerpts on pastie may provide some helpful advice for others trying to troubleshoot. In particular from #fl00r and #Kelvin:
run which -a for gem, bundle, rails, rake, etc. to see the available versions. Check to see which versions of ruby are being called with head -1 on each.
Original Below
Pretty much at my wit's end after a few days of Googling, uninstalling, and re-installing. I'm trying to get rails running on Mac OS X 10.6.7. I followed the Hivelogic Post on this topic. Apologize for the length of this question.
Has anyone followed a step-by-step uninstall/reinstall process for getting this working? Or a link to advice on troubleshooting? Should I clean out everything following this advice from Chad Wooley and migrate to RVM?
The common theme has been errors related to being unable to find gems even though they are installed. For instance, trying to create a new rails app:
kevindewalt#new-host-4:~/Documents$ $ rails new blog
You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install
Or an existing app I have running on another machine after running bundle install:
kevindewalt#new-host-4:~/Documents/ClaimAway$ (master) $ rake db:setup
(in /Users/kevindewalt/Documents/ClaimAway)
Could not find i18n-0.4.2 in any of the sources
Try running `bundle install`.
kevindewalt#new-host-4:~/Documents/ClaimAway$ (master) $ rails s
/usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch.rb:35:in `require': no such file to load --
-
kevindewalt#new-host-4:~/Documents$ $ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.7.0]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- /Users/kevindewalt/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
-
kevindewalt#new-host-4:~/Documents$ $ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
-
kevindewalt#new-host-4:~/Documents$ $ which -a ruby
/usr/local/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
/usr/local/bin/ruby

add to Gemfile
gem 'i18n'
Actually you should specify exact version also:
gem 'i18n', '0.4.2'
then run bundle install. But as far your i18n gem will be locked try this:
bundle update i18n
That is all what is written in your error.

rvm is probably your best bet to prevent problems like this. But it might be overkill if you actually don't need multiple ruby version or gemsets.
Let me try to diagnose the issue. If we can solve it, then you don't have to jump through the rvm hoops (unless you want to of course).
I suspect that when you run some of these ruby-based scripts like 'gem', 'bundle', 'rails', and 'rake' the shebang line of these scripts is pointing to a ruby installation that you didn't expect.
Here's my usual checklist of diagnosing gem issues like this.
Run "which -a gem". Do you see multiple unique locations? If so, gem list using the full path to gem. E.g. "/usr/bin/gem list" and "/usr/local/bin/gem list". My guess is that you'll see that one of the lists has i18n and the other doesn't.
Run "which" on rails, bundler, and gem. Run "head -1" on each of those paths. Does the ruby path match in all of them?
My guess is that the "rails" in your PATH is not using the same ruby as the "gem" in your PATH. Maybe you installed it with the preinstalled 'gem' command so it's pointing to the system ruby's gem directory rather than /usr/local. Try reinstalling rails, then closing and reopening your terminal. Then use the "which" and "head -1" above to make sure "rails" is using the same ruby as "gem" is.
Another suspect is the "sudo" command. You may also want to run the "which" command via sudo, e.g. sudo sh -c 'which gem'. It's possible that sudo is running one of the preinstalled scripts.
If in doubt, you could run: "sudo /usr/local/bin/gem install rails" so you know for sure which gem command you're using.

I would do a couple of things.
Start by uninstalling Rails >= 3 from your current systems gem installation. This includes all Rails dependencies. You should be able to boot < Rails3 projects using your normal gem installation now.
Next up install rvm and use rvm to install Ruby 1.9.2 and Rails3. Use the 1.9.2 rvm to work with your Rails3 projects. Part of rails3 and rails2 don't work well together so you should always try to seperate them imho.

See this stack question for step by step instructions for installing rails using rvm. This is the most tried and true method I've found:
Uninstall Ruby on Rails on Mac OS X 10.6

Related

Rails - Closed terminal and rebooted machine - now bash tells me rails isn't installed

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails and made it about 1/2 way through yesterday. When I stopped for the day, I closed out iTerm2 and shut off the Macbook Pro. Today, I powered up, opened iTerm, navigated to my working directory (~/rubyonrails/learn-ruby) and entered rails -v.
I see this:
`Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.`
So I run sudo gem install rails and it shows that it has installed rails-4.1.0. Now rails -v still gives me the same error message above.
I tried also running rvm use ruby-2.1.1#learn-rails first and I still get the error message.
So I'm a little stuck and I can't figure out what to do to get rails working. Also, how do I go about setting up the bash environment such that I don't have to go through this each time? It would be nice to nav to my working directory and just start work without having to do a bunch of re-installation and reconfiguration each time.
Regards,
Jeff
please type in your shell:
$ bash --login
and then repeat your commands.
rails -v
Also try to call it with the full path:
like:
/your/path/to/rails -v
I think that the shell just doesn't know where rvm/rails etc is located.
You can solve this by entering:
$ source ~/.rvm/scripts/rvm
When you switch to the ruby-2.1.1#learn-rails ruby/gemset combo, and do gem list, what do you see?
The way people usually use rvm is to have every project folder specify the ruby & gemset it uses (they don't all have to be different). This is done with files called .ruby-version and .ruby-gemset. These should contain, in your case, ruby-2.1.1 and learn-rails respectively.
Set these if you haven't already, then leave the folder and enter it again. Then do bundle install to install the gems for the project into the rvm/gemset combo.
Your problem is that you ran
sudo gem install rails
The error message telling you to do this comes from your system Ruby, which doesn't know that you want to use RVM.
RVM installs gems into your user-space directory. By using sudo, you're bypassing this and installing it into (effectively) the superuser space, i.e. globally.
If you instead just run
gem install rails
then you'll be using RVM's copy of the gem utility rather than the globally installed version.

Rails - the newest gem is installed but the applicaiton is old

I'm working on Bluehost. I installed the 3.2.8 gem of rails, and now I get this:
> gem list --local | grep rails
rails (3.2.8)
But:
rails --version
Rails 2.3.11
How can I make the "rails" command use the latest gem? I guess it has something to do with my $PATH variable but I'm pretty much clueless about it.
Also, the gem and rails command give rise to some errors that look like this:
Invalid gemspec in [XXX]: invalid date format in specification: "YYY"
I'm not sure if that's connected (and I'm wondering what causes such errors anyway).
Try running this command:
curl -L https://get.rvm.io | bash -s stable --ruby --rails
What it does is install RVM, which maintains separate gems for each version of Ruby installed. The --ruby and --rails arguments tell it to install ruby and rails while installing RVM. RVM installation automatically updates $PATH and any other necessary environment variables.
At the end of installation, it should prompt you to run:
source ~/.rvm/scripts/rvm
which will make those environment variable changes effective immediately. Alternatively, you can log out and then log right back in.
Run rails -v and ruby -v at that point, and you should see them pointing to the new version. Run bundle install from your RoR app's directory and all the gems you need should install in ~/.rvm/gems/ruby-/gems.
At that point, you can delete/uninstall any gems/rails/ruby from before installing RVM.
EDIT on 10/17/2012:
Nevermind my answer. Even though it might be possible to get Rails 3.x running with the currently installed Ruby 1.8 (see this Stackoverflow question), you won't be able to run Ruby 1.9.x using Bluehost Shared Hosting. Your only choice (for now) is VPS Hosting.
The reason is that Passenger Phusion is tied to the version of Ruby installed in /usr/lib, which you can't change without root access. Even though you can install any version of Ruby with RVM, you won't get Passenger to talk to it and therefore your rails project won't use its gems.

Rails version stuck at 2.3.5 how to update to 3.x

Hi there thanks for looking into this.
after a clean install of Linux ubuntu 10.10 i tried to re-install rails.
after doing sudo gem install rails, I can see I am returned version 3.2.3 of rails
But after generating a new project i couldn't find my gemfile so i tried ruby -v which returns 2.3.4 wich is odd since I know I got the latest.
Also when trying sudo gem update --system I get an error because I might override system files. any solution here?
I'd recommend using rvm to manage your ruby sets -- as well as defining gemsets for each project that will allow you to make sure each project has just the gems it needs.
Here's a link to the rvm installation instructions (they should work with ubuntu):
https://rvm.io/rvm/install/
Here's some info on basic use of gemsets with rvm:
https://rvm.io/gemsets/basics/
Also, when using rails 3+, you should make a practice of typing bundle exec rails -v -- that way you'll use the gems defined for the project you're in.
Can you try typing bundle exec rails -v and letting us know what you see?

After upgrading Ruby1.9.2 from p180 to p290, libruby dynamic library path isn't updated

I used RVM to upgrade Ruby 1.9.2 from patch level p180 to p290:
rvm upgrade 1.9.2-p180 1.9.2-p290
Then, I used these commands to update my Rails gem and other gems
gem install rails 3.0.5
gem update
Everything seems to be fine; rvm info shows all Ruby binaries and gems have been moved to the correct p290 path (~/.rvm/*/ruby-1.9.2-p290/*).
However, when I go to my Rails application directory and issue the command rails console, I get the error message saying a gem (activesupport-3.0.5) cannot load the libruby.1.9.1.dylib file.
10:30 AM ~/Development/rails_projects/my_app_0515 $ rails console
/Users/whk/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in `require': dlopen(/Users/whk/.rvm/gems/ruby-1.9.2-p290/gems/serialport-1.0.4/lib/serialport.bundle, 9): Library not loaded: /Users/whk/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.1.9.1.dylib (LoadError)
Referenced from: /Users/whk/.rvm/gems/ruby-1.9.2-p290/gems/serialport-1.0.4/lib/serialport.bundle
Reason: image not found - /Users/whk/.rvm/gems/ruby-1.9.2-p290/gems/serialport-1.0.4/lib/serialport.bundle
. . .
Rails can't find the dylib file in ~/.rvm/rubies/ruby-1.9.2-p180/lib, because the p180 path no longer exists, but the file is in ~/.rvm/rubies/ruby-1.9.2-p290/lib.
From a separate StackOverflow post, I found a workaround is adding this line to .bashrc
export DYLD_LIBRARY_PATH="/Users/whk/.rvm/rubies/ruby-1.9.2-p290/lib:$DYLD_LIBRARY_PATH"
However, I want to understand why the rvm ruby upgrade doesn't take care of the lib path change? Does anyone know a cleaner solution -- one that removes the p180 path from where it is configured?
Here are my environment:
Mac OS X 10.6.6 (Snow Leopard)
rvm 1.8.4
ruby 1.9.2p290
Rails 3.0.5
Thanks!
the problem was in gems native extension - their were nto rebuild during rvm upgrade 1.9.2-p180 1.9.2-p290 - next time please have closer look on the output ... it should give your information what's wrong.
as for this particular use case it shoudl be enough to reinstall the given gem:
gem install serialport -v 1.0.4
... not sure if it should be uninstalled first

no such file to load -- rubygems (LoadError)

I recently installed rails in fedora 12. I'm new to linux as well. Everything works fine on Windows 7. But I'm facing lot of problems in linux. Help please!
I've installed all the essentials to my knowledge to get the basic script/server up and running. I have this error from boot.rb popping up when I try script/server. Some of the details I'd like to give here:
The directories where rails, ruby and gem are installed,
[vineeth#localhost my_app]$ which ruby
/usr/local/bin/ruby
[vineeth#localhost my_app]$ which rails
/usr/bin/rails
[vineeth#localhost my_app]$ which gem
/usr/bin/gem
And when I run the script/server, this is the error.
[vineeth#localhost my_app]$ script/server
./script/../config/boot.rb:9:in `require': no such file to load -- rubygems (LoadError)
from ./script/../config/boot.rb:9
from script/server:2:in `require'
from script/server:2
And the PATH file looks like this
[vineeth#localhost my_app]$ 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="/usr/local/bin:/usr/local/sbin:/usr/bin/ruby:$PATH"
I suppose it is something to do with the PATH file. Let me know what I need to change here. If there are other changes I should make, please let me know.
I have a hunch that you have two ruby versions. Please paste the output of following command:
$ which -a ruby
updated regarding to the comment:
Nuke one version and leave only one. I had same problem with two versions looking at different locations for gems. Had me going crazy for few weeks. Put up a bounty here at SO got me same answer I'm giving to you.
All I did was nuke one installation of ruby and left the one managable via ports. I'd suggest doing this:
Remove ruby version installed via ports (yum or whatever package manager).
Remove ruby version that came with OS (hardcore rm by hand).
Install ruby version from ports with different prefix (/usr instead of /usr/local)
Reinstall rubygems
I had a similar problem on Ubuntu due to having multiple copies of ruby installed. (1.8 and 1.9.1) Unfortunately I need both of them. The solution is to use:
$ sudo update-alternatives --config ruby
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/ruby1.8 50 auto mode
1 /usr/bin/ruby1.8 50 manual mode
2 /usr/bin/ruby1.9.1 10 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/ruby1.9.1 to provide /usr/bin/ruby (ruby) in manual mode.
After doing that bundle install succeeded.
OK, I am a Ruby noob, but I did get this fixed slightly differently than the answers here, so hopefully this helps someone else (tl;dr: I used RVM to switch the system Ruby version to the same one expected by rubygems).
First off, listing all Rubies as mentioned by Eimantas was a great starting point:
> which -a ruby
/opt/local/bin/ruby
/Users/Brian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/Brian/.rvm/bin/ruby
/usr/bin/ruby
/opt/local/bin/ruby
The default Ruby instance in use by the system appeared to be 1.8.7:
> ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]
while the version in use by Rubygems was the 1.9.2 version managed by RVM:
> gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /Users/Brian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
So that was definitely the issue. I don't actively use Ruby myself (this is simply a dependency of a build system script I'm trying to run) so I didn't care which version was active for other purposes. Since rubygems expected the 1.9.2 that was already managed by RVM, I simply used RVM to switch the system to use the 1.9.2 version as the default:
> rvm use 1.9.2
Using /Users/Brian/.rvm/gems/ruby-1.9.2-p290
> ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.3.0]
After doing that my "no such file" issue went away and my script started working.
I would just like to add that in my case rubygems wasn't installed.
Running sudo apt-get install rubygems solved the issue!
Try starting the project with:
./script/server
instead of script/server if you are using ruby 1.9.2 (from strange inability to require config/boot after upgrading to ruby 1.9.2)
In case anyone else is googling this problem: I was able to fix mine by finding the elusive "rubygems" folder that I wanted to use and adding it to my $RUBYLIB environment variable.
find / -name "rubygems" -print
Once you find it, add the parent directory to your environment. In bash, like so:
export RUBYLIB=/path/to/parent
Now if you run gem, it should pick up the right library directory, and you're off and running.
I had a similar problem, simply running a trivial ruby script that just required the gem i wanted...got that error message. When I changed the incantation from:
ruby test.rb
to
ruby -rubygems test.rb
Seemed to work.
I had a similar problem and solved that by setting up RUBYLIB env.
In my environment I used this:
export RUBYLIB=$ruby_dir/lib/ruby/1.9.1/:$ruby_dir/lib/ruby/1.9.1/i686-linux/:$RUBYLIB
If you have several ruby installed, it might be sufficient just to remove one of them, on MacosX with extra ports install, remove the ports ruby installation with:
sudo port -f uninstall ruby
I also had this issue.
My solution is remove file Gemfile.lock, and install gems again: bundle install
gem install bundler
fixed the issue for me.
This is the first answer when Googling 'require': cannot load such file -- ubygems (LoadError) after Google autocorrected "ubygems" to "rubygems". Turns out this was an intentional change between Ruby 2.4 and 2.5 (Bug #14322). Scripts that detect the user gems directory without taking into account the ruby version will most likely fail.
Ruby 2.4
ruby -rubygems -e 'puts Gem.user_dir'
Ruby 2.5
ruby -rrubygems -e 'puts Gem.user_dir'
I have also met the same problem using rbenv + passenger + nginx. my solution is simply adding these 2 line of code to your nginx config:
passenger_default_user root;
passenger_default_group root;
the detailed answer is here: https://stackoverflow.com/a/15777738/445908
Simply running /bin/bash --login did the trick for me, weirdly. Can't explain it.

Resources