I can't seem to get rails installed on my Mac (10.6.5). Following Ruby on Rails Tutorial 3 - ruby-on-rails-3

I'm trying to get Rails 3 up and running by following the steps outlined in "Ruby on Rails Tutorial" by Michael Hartl (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book).
The details start in section 1.2.2 (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:rubygems). Here you go through the following steps:
Installing Git
Installing Ruby (version 1.9.2) using Ruby Version Manager (RVM)
Creating different gemsets for environments using Ruby 1.8.7 and 1.9.2
Installing RubyGems
and finally, installing Rails.
I run the following command [sudo] gem install rails --version 3.0.7
Everything seemed to install correctly (based on no errors). However, when I type "rails -v", rails cannot be found.
I am a Rails newbie. I'm trying to install Rails on a machine running Mac OS X 10.6.7.
Thanks.

If you are using RVM you probably don't want to use sudo when installing gems. If you have Git installed only steps needed to get Rails are:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.zshrc
# Reload your shell now (open a new terminal for example)
rvm install 1.9.2
rvm 1.9.2 --default
gem install rails --version 3.0.7
hash -r
This skips the gemsets part (you don't need it if you are just starting learning Rails) and assumes that you use Zsh (I think it's Mac OS X default, if you use Bash then you have to alter .bashrc, not .zshrc).
If you want to remove your previous installation and start over use rvm implode.

Related

Ruby cannot find gem in gemset

I apologize if I've missed something obvious. I am new to Ruby.
My overall goal is to add functionality to an existing script, which is using rvm and gemsets.
When I install new gems to a particular gemset, the requires in my scripts fail to find them. I am using the following rvm instance:
$ rvm current
jruby-1.6.7.2#preflight
To confirm:
$ which ruby
/Users/user/.rvm/rubies/jruby-1.6.7.2/bin/ruby
$ ruby -v
jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.8.0_11) [darwin-x86_64-java]
I specified the gemset into I install a given gem (let's say xml-simple).
$ rvm #preflight do gem install xml-simple
Successfully installed xml-simple-1.1.5
1 gem installed
To verify the gem installed correctly:
$ gem list
*** LOCAL GEMS ***
...
xml-simple (1.1.5)
...
We see the module I installed there.
Following the xml-simple instructions to include the module, I run this script:
require 'xmlsimple'
which, results in:
$ ruby testver.rb
LoadError: no such file to load -- xmlsimple
require at org/jruby/RubyKernel.java:1033
(root) at testver.rb:1
One suspicious thing I have seen is that printing out RUBY_VERSION and $LOAD_PATH shows me this:
$ ruby testver.rb
1.8.7
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/1.8
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/site_ruby/shared
/Users/user/.rvm/rubies/jruby-1.6.7.2/lib/ruby/1.8
.
Adding require "rubygems" is required prior to Ruby version 1.9.2, per this stackoverflow answer. This resolved my issue.

Ruby keeps reverting to an old version

I am having some issues with RVM on Ubuntu. My computer is currently set to dual boot with windows 7 if that matters. I am trying to run the latest version of ruby 1.9.3. Each time I close terminal, it will revert to 1.8.7 despite using rvm use 1.9.3 --default. The following was the steps I was using.
michael#michael-Studio-XPS-1640:~$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
michael#michael-Studio-XPS-1640:~$ 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.
michael#michael-Studio-XPS-1640:~$ /bin/bash --login
michael#michael-Studio-XPS-1640:~$ rvm use 1.9.3 --default
Using /home/michael/.rvm/gems/ruby-1.9.3-p286
michael#michael-Studio-XPS-1640:~$ ruby -v
ruby 1.9.3p286 (2012-10-12 revision 37165) [i686-linux]
After I close and reopen the terminal I get the following verion info. I also added the rvm list information as well.
michael#michael-Studio-XPS-1640:~$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
michael#michael-Studio-XPS-1640:~$ rvm list
rvm rubies
=* ruby-1.9.3-p286 [ i686 ]
# => - current
# =* - current && default
# * - default
Thank you guys in advance.
you missed the displayed instructions:
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.

Passenger on Apache 2 Installation fails with Your RVM wrapper scripts are too old

I'm trying to install passenger on a virtual rootserver (which has multiple user accounts) but running 'passenger-install-apache2-module' results always in the following error:
Your RVM wrapper scripts are too old. Please update them first by running 'rvm get head && rvm reload && rvm repair all'.
Following this given instructions does not take any effect.
Before installing passenger, i installed RVM as multiuser / mixed mode according to https://rvm.io//rvm/install/
After that I did (using a non root-account):
rvmsudo rvm user gemsets
rvm install 1.9.3
gem install rails
gem install passenger
and lastly passenger-install-apache2-module
I searched for hours on this problem but could not find any working solution yet.
Any suggestions ? Thanks in advance!
Try to install passenger-install-apache2-module like this :
rvmsudo passenger-install-apache2-module
I just encountered this very same issue. I'm using ZSH, but switching to Bash also failed on first attempt.
My solution was to switch to Bash with the --login flag:
/bin/bash --login
Then I noticed that my RVM ruby had become unset, so I re-set using:
rvm use ruby-1.9.3 --default
Once this was done, the following worked as expected:
passenger-install-apache2-module
Rich
I have had similar issue and have taken extreme steps on my centos 6.3 system after struggling for days! In specific, I failed to install standalone phusion passenger apache2 module on gemsets other than default and global. I have taken the following steps and now, it works for me:
Login as root (I hope you know what you're dealing with)
To completely uninstall existing rvm, invoke
[root#] rvm implode
Install stable rvm, invoke
[root#] curl -L get.rvm.io | bash -s stable
run rvm shell,
[root#] source /etc/profile.d/rvm.sh
check rvm requirements, invoke
[root#] rvm requirements
and install all requirements.
Install ruby 1.9.3, invoke
[root#] rvm install 1.9.3
Install current rubygems, invoke
rvm rubygems current
Set default to ruby 1.9.3, invoke
[root#] rvm use 1.9.3 --default
Add other users who are using rvm to rvm group, invoke
[root#] usermod -a -G rvm USERNAME
If USERNAME is currently logged in, pls logout so the group add will take effect.
Make sure rvm group added, invoke
[USERNAME#] groups
Create and Switch to a new gemset on ruby 1.9.3, invoke
[USERNAME#] rvm use 1.9.3#mygemset --create
Confirm that you're on the right gemset, invoke
[USERNAME#] rvm gemset name
Install passenger gem, invoke
gem install passenger
To skip gem documentation instead, invoke
[USERNAME#] gem install passenger --no-ri --no-rdoc
or specify them in your .gemrc file
To install apache2 mod, invoke
[USERNAME#] passenger-install-apache2-module
Hope that helps!

Cannot get the basic rails tutorial to work on OS X Lion

I've been trying to get this introduction to work:
http://guides.rubyonrails.org/getting_started.html
When I try this step 'rails generate scaffold Post name:string title:string content:text' I get the following:
Cerberus:app lab49$ rails generate scaffold Post name:string title:string content:text
invoke active_record
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:66:in connection_url_to_hash': undefined methodsub' for nil:NilClass (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:34:in block in resolve_string_connection'
from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activerecord->3.2.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:33:infetch'
I'm using ruby-1.9.3-p194 and rails 3.2.6 on Mac OS X Lion 10.7.4.
I've spent the last few days searching the interwebs for a solution. The only progress I made was by downgrading to rails 3.1.6, but then that introduces a bug with saving models.
Any help would be much appreciated.
Did you install iconv and readline? http://blog.merjis.com/2011/12/18/rails-3-1-ruby-1-9-3-lion-xcode-4-1/
I compiled ruby 1.9.3p194 from source but I first had to compile libyaml from source.
Remove/move the defaults files in /usr/bin
sudo mv rails rails-old
sudo mv bundle bundle-old
sudo mv ruby ruby-old
sudo mv gem gem-old
Compile libyaml
cd libyaml-x.x.x
./configure
make
make install
Compile ruby (prefix will tell it where to install during make install and with-opt-dir will tell it where to find libraries such as readline, libyaml etc. Lion should already have them in the directory if you installed xcode)
./configure --prefix=/usr/local --with-opt-dir=/usr/local/lib
make
make install
Install rails
gem install rails

Rails 3: Ruby 1.9.2: does it need /usr/bin/ruby1.8?

I am trying to get the Rails tutorial by Michael Hartl going. I spent a lot of time fighting various libraries. So I removed all ruby software from my Ubuntu 10.4 system.
Then I installed Ruby 1.9.2.
$ ruby -v
ruby 1.9.2dev (2010-07-02) [i486-linux]
So far so good. Then I did
sudo gem install rails
After a long time, it finished the installation.
Then I ran
$ rails -v
bash: /usr/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file or directory
So...I have no /usr/bin/ruby1.8 on my system. How do I get Rails 3.0.3 to use my ruby at /usr/bin/ruby?
I appreciate any help you can give me.
Just to see if I could keep going, I tried
$ cd /usr/bin
$ sudo ln -s ruby1.9.2 ruby1.8
This let me keep going, but is it the right thing to do?
It took trying 3 different methods of installing and uninstalling Ruby, but I finally got it!
I found a great tutorial by Toran Billups which gives some great instructions. After analyzing what he did, it comes down to a few key concepts:
Some libraries that are independent of the Ruby version must be installed in the system (using "sudo apt-get").
Use RVM to install Ruby in your own account. i.e. no "sudo".
Use gem to install gems in your particular ruby environment. (i.e. no "sudo"). When you set 1.8 as the Ruby environment, the gems are installed in the RVM 1.8 tree in your environment. When you set 1.9.2 as the environment, gems are installed in the 1.9.2 tree in your environment.
Here, then, is the process.
Remove all Ruby programs (1.8.x and 1.9.2) and Ruby libraries from your Ubuntu 10.4 system.
Install RVM on your system, following the instructions at the RVM site(broken) RVM site.
Follow Toran Billups' tutorial, starting at the point where you install Ruby 1.8.7.
Follow the instructions at Michael Hartl's tutorial(broken) Michael Hartl's tutorial to get Rails 3.0 working with Ruby 1.9.2, github, heroku.com, rspec, spork, and autotest.
I had the same error after installing with RVM and opening new shells. The solution was to run:
$ rvm use 1.9.2 --default
P.S.
I'm running Ubuntu 10.04 and after two days of trial and error finally got rails 3 working with ruby 1.9.2. I highly recommend using RVM to install ruby a godsend!
By the sounds of it Bash is finding ruby1.8 when its running the #!/usr/bin/env ruby line from the rails script, even though it doesn't exist. Try /usr/bin/env which ruby to see exactly what interpreter it's trying to load.
I was also having a headache with this, and don't want to use RVM right now.
I saw that the shebang line for /usr/bin/gem was #!/usr/bin/ruby1.8 and that this was presumably the issue.
I made sure /etc/alternatives pointed to the correct gem script; this can be set with:
update-alternatives --config gem
Then I removed /usr/bin/gem and symlinked from /usr/bin/gem to /etc/alternatives/gem
It turns out the only difference in the gem scripts was the shebang line, so manually changing that would have worked too.
Solved by changing back the version of my current Ruby (using RVM) to 2.0.x.
When i installed rails (two days ago) it was under the 2.0.0 version. Yesterday i changed to 2.1.x. Today i tried the rails command and got the error.
So turning back to the RVM Ruby version i installed rails did the trick.
Sorry by the bad english.
P.S. Using Ubuntu 13.10