accidentally created a rails app in the home folder

Im a new user - I just installed rails, following directions here:
http://rubyonrails.org/download
however, when it came time to make a rails new path/etc/etc I get this
message:
Can't initialize a new Rails application within the directory of
another, please change to a non-Rails directory first.
The only complication during the download was that I had to upgrade from
version 1.8.6 to 1.9.3, which I did after installing rails. Otherwise
Ive done nothing but follow the very simple directions.
I found this very helpful thread http://www.ruby-forum.com/topic/1780147
but when the output of ls -l shows just my usual directories. Any help
is greatly appreciated.

So, what happens if you make a new directory, cd to it, and run your
`rails new blah` command?

exact same thing

exact same thing

In an empty directory? Then I'd say you have serious problems.

The only complication during the download was that I had to
upgrade from version 1.8.6 to 1.9.3, which I did after installing rails.

Wait, *after* installing Rails? That, in retrospect, sounds bad. What
OS/platform are you on?

And what do you get from the following commands:
ruby -v
rails -v
gem -v

ruby -v gives ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]
rails -v gives Rails 3.2.13
gem -v gives 1.8.25

Im running ubuntu. I had ruby 1.8.6. I installed gem but it gave an
error when I was trying to get rails through gem, bc i had the old
version of ruby. I got rvm, updated to 1.9.3 and then reinstalled rails.

It does indeed give the same " Can't initialize a new Rails application
within the directory of another, please change to a non-Rails directory
first" when Im in an empty directory I made from home.

Thank you for your help by the way.

What is the command you are using to create a new rails app? Just to be sure, type the command into a terminal window and copy / paste the command you typed and the output from rails.

Those seem reasonable, though the result doesn't :-/

Given that you're just starting, I'd be inclined to totally remove rvm
(rvm implode), make sure that your old system ruby has no trace
of rails or related gems, and then reinstall rvm, 1.9.3, and rails.

Slash and burn, but ... with a quick look at the source, I don't see
how you're getting that message...

There are (at least) two executable ruby scripts named “rails”. The first is found in your typical search path and should be the one that gets called when you type “rails new my_app”. The second is found, after creating your new application “my_app”, in the directory “my_app/script” (rails version 3) or “my_app/bin” (rails version 4).

These ruby scripts named “rails” are not the same and, if you call the second with the “new my_app” arguments, “rails” will assume you are running inside an existing application and hurl error chunks at you.

Do this

  1. type the command “which rails” and you will see the full path to what your current shell assumes to be the true rails command.

i.e. on my system
555 > which rails
/opt/local/bin/rails
556 >

  1. type the command "wc -l which rails" – if you can’t figure out the quoting just use the result of step 1. i.e. on my system “which /opt/local/bin/rails”

you should see a result that is somewhere around 23 (lines) but i’m thinking you’ll see 6. the first number is the correct system wide rails script that will let you create a new app, the second number is the rails script that is placed into “my_app/script” (or “my_app/bin”) and will be used when you “rails generate …” or other such inside your new application directory structure.

just to beat this horse to death, here’s what i get when, in my home directory, i call an application (6 line) rails with new…

561 > binky/script/rails new boffo
Can’t initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
Type ‘rails’ for help.
562 >

look familiar?

for what it’s worth, the error message is generated in the file: gems/railties-3.2.13/lib/rails/commands.rb

Hassan Schroeder wrote in post #1110852:

Hi Rick,
thanks! I tried carrying out those instructions: heres what i got -
mwr@mwr-Ubuntu:/home$ which rails
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails

mwr@mwr-Ubuntu:/home$ which
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails

I suppose im having trouble with step 2 of your directions. However its
nice to have a kind of explanation of whats going on. Again, excuse my
illiteracy on this, but it look like maybe i do have rails installed in
my home directory?

**just discovered by accident I can do this:
mwr@mwr-Ubuntu:/home$ which
/home/mwr/.rvm.gems/ruby-1.9.3-p429/bin/rails
mwr@mwr-Ubuntu:/home$ wc -l 'which rails'
wc: which rails: No such file or directory
mwr@mwr-Ubuntu:/home$ cd ..
mwr@mwr-Ubuntu:/$ which rails
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails
mwr@mwr-Ubuntu:/$ which /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails
mwr@mwr-Ubuntu:/$ rails new path/here
      create
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:247:in
`mkdir': Permission denied - /path (Errno::EACCES)
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:247:in
`fu_mkdir'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:221:in
`block (2 levels) in mkdir_p'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:219:in
`reverse_each'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:219:in
`block in mkdir_p'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:205:in
`each'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/fileutils.rb:205:in
`mkdir_p'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:51:in
`block in invoke!'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:117:in
`call'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:117:in
`invoke_with_conflict_check'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:50:in
`invoke!'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions.rb:95:in
`action'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:15:in
`empty_directory'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/generators/app_base.rb:103:in
`create_root'
  from (eval):1:in `create_root'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/command.rb:27:in
`run'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/invocation.rb:120:in
`invoke_command'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/invocation.rb:127:in
`block in invoke_all'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/invocation.rb:127:in
`each'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/invocation.rb:127:in
`map'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/invocation.rb:127:in
`invoke_all'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/group.rb:233:in
`dispatch'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/thor-0.18.1/lib/thor/base.rb:439:in
`start'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/commands/application.rb:38:in
`<top (required)>'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/lib/rails/cli.rb:15:in
`<top (required)>'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/home/mwr/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
/home/mwr/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.13/bin/rails:7:in
`<top (required)>'
  from /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails:19:in `load'
  from /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails:19:in `<main>'
  from /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in
`eval'
  from /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in
`<main>'
mwr@mwr-Ubuntu:/$ ls
bin dev initrd.img lib64 mnt root selinux tmp
vmlinuz
boot etc initrd.img.old lost+found opt run srv usr
vmlinuz.old
cdrom home lib media proc sbin sys var

Im a new user - I just installed rails, following directions here:
http://rubyonrails.org/download
however, when it came time to make a rails new path/etc/etc I get this
message:
Can't initialize a new Rails application within the directory of
another, please change to a non-Rails directory first.

Rather than specifying a complex path to the new application (my guess
is that you have already created a rails app in path/etc/etc, so it
will not let you create a new one there) just cd to, for example your
home directory using
cd ~
then create an app called, for example, myapp
rails new myapp

Colin

i now see i misstyped the instructions to step 2. here it is, corrected
2) type the command "wc -l which rails" – if you can’t figure out the
quoting just use the result of step 1. i.e. on my system “wc -l /opt/local/bin/rails”
the idea is to use the wc command to get the number of lined in the rails script you are calling by default. the quoting used in wc -l which rails an open single quote - on a mac keyboard it’s found on the key to the left of number one. it’s a bit of unix shell magic that causes the quoted text to be evalulated as a command and the results to be handed off the the wc -l command as argument(s). thus, on my system, it becomes wc -l /opt/local/bin/rails.
in your case wc -l which rails would be equivalent to wc -l /home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails and i’ll be surprised if the result is much greater than 6. i don’t use rvm so cannot help you troubleshoot rvm specific errors. i can say that you don’t want to be creating your new app anywhere inside the …/.rvm/… directory tree. think of this as a managed software repository - anything that gets changed there is done through rvm. make yourself a working directory, cd there and run the rails new command. something like:
mkdir /home/mwr/RailsApps
cd /home/mwr/RailsApps
rails new my_new_app

Alright, now its working kind of! After restarting the computer and
using which rails i get the much more sensible looking path *
/usr/local/bin/rails *
running wc -l `which path` I get * 19 /usr/local/bin/rails *

so now navigating above my home directory I am able to use rails new
like so: * mwr@mwr-Ubuntu:/$ sudo rails new blah/here * and it seems to
work.

now - i cant access my localhost, but thats a separate issue i think i
can work out.

Thanks everyone for your help!

Alright, now its working kind of! After restarting the computer and
using which rails i get the much more sensible looking path *
/usr/local/bin/rails *
running wc -l `which path` I get * 19 /usr/local/bin/rails *

so now navigating above my home directory I am able to use rails new
like so: * mwr@mwr-Ubuntu:/$ sudo rails new blah/here * and it seems to
work.

Don't use sudo, you will get the wrong ownership on the files

Also I recommend using rvm to install ruby and rails.

now - i cant access my localhost, but thats a separate issue i think i
can work out.

Possibly due to using sudo when creating the app.

Colin

just an update/follow up. I can successfully run rails and get a rails
server going on my localhost. However, my paths remain totally messed up
and I dont know why. I get the error I originally posted about anywhere
I go (and I am completely certain I am not inside a path that already
has a rails app in it) except, if I go above my home file into my what i
call my root file, it looks like this.
mwr@mwr-Ubuntu:/home$ cd ..
mwr@mwr-Ubuntu:/$ cd ..
mwr@mwr-Ubuntu:/$ ls
app cdrom initrd.img lost+found proc selinux usr
bin dev initrd.img.old media root srv var
blah etc lib mnt run sys vmlinuz
boot home lib64 opt sbin tmp vmlinuz.old
mwr@mwr-Ubuntu:/$

my understanding is this cant really be right. To get a rails project
working I have to type sudo for every single command i give, from mkdir
to rails new app etc. But there is nowhere else in my system where i can
run rails new and this was true from the very first time I tried to run
it.
I attempted to uninstall rails, but even though it seemed I did, running
'which rails' would always yield a result. I wound up reinstalling
anyways.

maybe this is just how it works? or have I made some sort of correctable
mistake?

That is not how it should work. I suggest starting again using rvm to
install rails. You don't actually need to get rid of anything you have
already installed but it will do no harm to do so. The rvm install
should take precedence over the existing messed up installation.

Colin

well, i tried rvm implode and a fresh install using these directions:
http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/

still same problem:
mwr@mwr-Ubuntu:~$ ls
app db Documents log Projects script tmp
build Desktop Downloads Music Public Templates vendor
config doc lib Pictures public test Videos
mwr@mwr-Ubuntu:~$ rails new blargh/here
Can't initialize a new Rails application within the directory of
another, please change to a non-Rails directory first.
Type 'rails' for help.
mwr@mwr-Ubuntu:~$ which rails
/home/mwr/.rvm/gems/ruby-1.9.3-p429/bin/rails
mwr@mwr-Ubuntu:~$ rails new blog
Can't initialize a new Rails application within the directory of
another, please change to a non-Rails directory first.
Type 'rails' for help.
mwr@mwr-Ubuntu:~$

Im at a loss, going to try to post to ubuntu specific forums. Thanks
everyone for your help and if I fix it I will post here in case it helps
someone else.

?? Your `ls` shows the directories of a standard Rails app, so the
message is perfectly understandable.

If you don't want them there, why don't you *remove* them?

Hassan Schroeder wrote in post #1111345: