$ rails server... undefined method `gem' for main:Object (NoMethodError) - ruby-on-rails-3

I'm new to Rails trying to complete this tutorial, but I can;t even get started.
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-rails_server
I am at Step 1.2.5
I am supposed to start the server using: $ rails server
I'm getting this error whenever I try to run any rails command.
localhost:first_app home$ rails server
/usr/bin/rails:22: undefined method `gem' for main:Object (NoMethodError)
Running rails commands used to work, because I had completed other tutorials from other books in the past. However, somewhere along the steps in this tutorial something was messed up.
Is it possible that editing my bash_profile caused this?
My bash_profile looks like this now:
export PATH=/bin:/usr/bin:"$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
I added this line to it: export PATH=/bin:/usr/bin:"$PATH" after following directions in step Listing 1.1. Creating a gem configuration file.
I'm not sure if this helps, but If I type:
$ which rails
I get:
/Users/home/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/bin/rails

Have you installed gem? type:
which gem
and see what you get. If you don't have gem or the wrong version, follow these instructions: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-install_rubygems

typing
$ rvm use 1.9.3#rails3tutorial2ndEd --create --default.
allowed me to continue.

I had a similar problem under ubuntu. I fixed it by changing gnome-terminal settings https://rvm.io/integration/gnome-terminal

Related

Run rails Webrick server from Sublime Text 3 using a custom Build System

I'm trying to create a build system which will run the following command:
rails server
Within the project's directory. I have tried the following which seems to make the build take around 5 seconds, but nothing is output and no errors show. When I test in bro2wser, it says "Page not found" so I know it hasn't ran the command correctly.
{
"cmd": ["rails", "server"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"working_dir": "${project}"
}
Any help would be fantastic.
EDIT:
Changed my build system to the following:
{
"cmd": ["rails", "server"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"working_dir": "${project_path}"
}
And now getting this build error:
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. [Finished in 0.0s]
When I run rails command in the terminal, it works fine. Bundle install shows that I'm "Using rails (3.2.8) ".

Passenger module fails to install

On Mac OSX 10.8.4, I'm running:
sudo passenger-install-apache2-module
which suggested:
Your RVM wrapper scripts are too old, or some wrapper scripts are missing. Please update/regenerate them first by running:
rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all
If that doesn't seem to work, please run:
rvmsudo rvm wrapper [] --no-prefix --all
I did the first bit, re-ran the passenger-install-apache2-module but got the same problem. Then I did the second part. This gave:
awk: nonterminated character class ^[]=
source line number 1
context is
>>> /^[]=/ <<<
sed: 1: "s#^[]=##
": unbalanced brackets ([])
Unknown ruby interpreter string component: '[]'.
Could not load ruby [].
Any suggestions on where I go from here?
just run passenger-install-apache2-module do not prefix it with sudo.
the command will tell you what to do if it has no write access into required locations.
using sudo losses all environment variables - which basically breaks what rvm set up.
if you would really need root privileges you should use rvmsudo which does preserve all required environment variables.

How can I get rails to use pg by default?

It's not a huge burden but I would really like to be able to change the default gem-set on my rails apps when I create them so that they're ready for Heroku.
What is the best way to go about doing this?
You can specify the database with -d when running rails new:
Usage:
rails new APP_PATH [options]
Options:
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
Description:
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
So for PostgreSQL this is:
rails new myapp -d postgresql
To make this the default put -d postgresql into ~/.railsrc
Another option is to change gem 'sqlite3' to gem 'pg' in your Gemfile as suggested in Getting Started with Rails 3.x on Heroku.

$ Command not found with "rails new app -m myfile.rb"

I'm trying to use the MongoID-Devise generator template by doing this under Ubuntu and using RVM:
rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb
I've also tried to download the file and do the generation locally, but in both cases, I get:
$: command not found
As according to the guides: Application Template, I'm using the command/options correctly...
EDIT:
The following commands gives me the following results:
rails -v --> Rails 3.1.3
ruby -v --> ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
The "$" you see at the beginning of the command is actually a convention that indicates a Unix console prompt. Don't include the "$".

RVM & Unicorn deploy

My RVM is installed as root.
When I'm trying to start unicorn socket, it prints
user#9001-3:~$ /etc/init.d/unicorn start
Starting myapp app: /usr/bin/env: ruby: No such file or directory
unicorn.
But if I type
user#9001-3:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/unicorn path exists.
My unicorn config: https://gist.github.com/1010519
/etc/init.d/unicorn doesn't know where to find Ruby because it's managed via RVM. Normally, your .bashrc or similar file is executed and sets up the environment; this doesn't happen in init scripts (or likely anything else executed by root).
The solution is to use wrappers. For example, to create a binary called system_ruby that loads up RVM's 1.9.2p180 environment and then executes ruby, execute the following:
rvm wrapper ruby-1.9.2-p180 system ruby
For more information and more details, check out this answer of mine, which addresses a similar problem.
Symlink also works,
which ruby<your version>
ln-s /ruby/path/ruby<your version> /ruby/path/ruby
Type :
which ruby (show the ruby bin path) then type this : ln -s (change_to_ruby_path) /usr/bin/env/ruby (construct the correct access for your system)
I had the same problem and this for me
rvm --default use <version>