Could not locate Gemfile - ruby

I'm certainly no Ruby developer but I have an application on my server using Ruby, Gems, and Bundler. I am trying to install another Ruby on under a different user account but on the same VPS. When I go to run
bundle install
I get the following error:
Could not locate Gemfile
I could remove the contents of the ./bundle directory so that all Gems are re-fetched to clear the error but will this have an impact on my other application using the same Gems and Bundler? I don't want to risk taking the other app down.

You do not have Gemfile in a directory where you run that command.
Gemfile is a file containing your gem settings for a current program.

Make sure you are in the project directory before running bundle install. For example, after running rails new myproject, you will want to cd myproject before running bundle install.

I had the same problem and got it solved by using a different directory.
bash-4.2$ bundle install
Could not locate Gemfile
bash-4.2$ pwd
/home/amit/redmine/redmine-2.2.2-0/apps/redmine
bash-4.2$ cd htdocs/
bash-4.2$ ls
app config db extra Gemfile lib plugins Rakefile script tmp
bin config.ru doc files Gemfile.lock log public README.rdoc test vendor
bash-4.2$ cd plugins/
bash-4.2$ bundle install
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.3.6)
Using activesupport (3.2.11)
Using builder (3.0.0)
Using activemodel (3.2.11)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.2.1)
Using actionpack (3.2.11)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.4)
Using actionmailer (3.2.11)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.11)
Using activeresource (3.2.11)
Using coderay (1.0.6)
Using rack-ssl (1.3.2)
Using json (1.7.5)
Using rdoc (3.12)
Using thor (0.15.4)
Using railties (3.2.11)
Using jquery-rails (2.0.3)
Using mysql2 (0.3.11)
Using net-ldap (0.3.1)
Using ruby-openid (2.1.8)
Using rack-openid (1.3.1)
Using bundler (1.2.3)
Using rails (3.2.11)
Using rmagick (2.13.1)
Your bundle i

I solved similar problem just by backing out of the project directory, then cd back into the project directory and bundle install.

Is very simple. when it says 'Could not locate Gemfile' it means in the folder you are currently in or a directory you are in, there is No a file named GemFile. Therefore in your command prompt give an explicit or full path of the there folder where such file name "Gemfile" is e.g cd C:\Users\Administrator\Desktop\RubyProject\demo.
It will definitely be solved in a minute.

I had to do touch Gemfile.
My case was an AWS Amazon Linux instance and Capistrano setting up Puma.

Here is something you could try.
Add this to any config files you use to run your app.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
Bundler.require(:default)
Rails and other Rack based apps use this scheme. It happens sometimes that you are trying to run things which are some directories deeper than your root where your Gemfile normally is located.
Of course you solved this problem for now but occasionally we all get into trouble with this finding the Gemfile. I sometimes like when you can have all you gems in the .bundle directory also.
It never hurts to keep this site address under your pillow.
http://bundler.io/

In my case, I was trying to run locally checked out rails code in a script
gem "rails", path: "../rails"
Running the script normally as ruby script.rb gave the error Could not locate Gemfile or .bundle/ directory (Bundler::GemfileNotFound)
Setting the Gemfile path similar to #douglasgallen solved it
BUNDLE_GEMFILE="../rails" ruby script.rb

Typo
Maybe a stupid solution, but I got a typo: Gemfile instead of GemFile. Hope this helps.

Related

"The gem ... has been deleted. It was installed at" Error. Bundle install doesn't install gems. How to re-install gems?

I'm trying to build capybara-webkit on XP. I follow this instruction. I says:
8) Clone latest version of capybara-webkit from Github:
$ git clone git://github.com/thoughtbot/capybara-webkit.git
9) Bundle/Install capybara-webkit version:
$ cd ruby193\capybara-webkit
$ bundle install
I did so at the first time. It installed some gems. Then I followed the instruction steps but couldn't build capybara-webkit. So to begin one more time, I deleted all the gems that were installed manually. Now I follow all the same steps but bundle install doesn't work any more. I says that all the gems are present:
C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems>cd capybara-webkit
C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\capybara-webkit>bundle install
Resolving dependencies...
Using rake (0.9.2)
Using addressable (2.3.2)
Using bundler (1.3.5)
Using appraisal (0.4.0)
Using mime-types (1.22)
Using nokogiri (1.5.9)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using xpath (2.0.0)
Using capybara (2.1.0)
Using json (1.8.0)
Using capybara-webkit (1.0.0) from source at .
Using ffi (1.2.0)
Using childprocess (0.3.6)
Using diff-lcs (1.1.2)
Using websocket (1.0.6)
Using libwebsocket (0.1.7.1)
Using subexec (0.0.4)
Using mini_magick (3.2.1)
Using multi_json (1.5.0)
Using rack-protection (1.3.2)
Using rspec-core (2.6.4)
Using rspec-expectations (2.6.0)
Using rspec-mocks (2.6.0)
Using rspec (2.6.0)
Using rubyzip (0.9.9)
Using selenium-webdriver (2.27.2)
Using tilt (1.3.3)
Using sinatra (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
But now I check these gems with bundle show but it says they all were deleted:
C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\capybara-webkit>bundle show sinatra
The gem sinatra has been deleted. It was installed at:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sinatra-1.3.5
C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\capybara-webkit>bundle show selenium-webdriver
The gem selenium-webdriver has been deleted. It was installed at:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.27.2
C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\capybara-webkit>bundle show mini_magick
The gem mini_magick has been deleted. It was installed at:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mini_magick-3.2.1
How it can be that bundle install says they are present but bundle show says they are deleted? So bundle install doesn't work any more. How may I again use bundle install to install these gems again?
This solved it for me: "gem install" and "bundle install" do not install gem dependencies after manual gem deletion. How to inform Rubygems that gems were deleted manually?
(Delete the .gemspec files for the gems you have removed).

Trying to update to gem 3.0.20 and install a DevKit

Heroku advised updating to this gem because of a security patch but it has caused me all kinds of headaches and now my local environment isn't working correctly. They suggested doing this as a security precaution. They suggested going into my app, changing the gemfile version and simply running 'bundle update rails'. Here was the output:
$ bundle update rails
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.20)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.20)
Using erubis (2.6.6)
Using rack (1.2.8)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.37)
Using actionpack (3.0.20)
Using mime-types (1.21)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.2.19)
Using actionmailer (3.0.20)
Using arel (2.0.10)
Using activerecord (3.0.20)
Using activeresource (3.0.20)
Using bundler (1.0.22)
Installing json (1.7.7) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
c:/Ruby192/bin/ruby.exe extconf.rb
creating Makefile
make
'make' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in c:/Ruby192/lib/ruby/gems/1.9.1/gems/json-1.7.7 for inspection.
Results logged to c:/Ruby192/lib/ruby/gems/1.9.1/gems/json-1.7.7/ext/json/ext/generator/gem_make.out
An error occured while installing json (1.7.7), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.7'` succeeds before bundling
Then they pointed to a thread on here of someone having a similar problem. It involved downloading a Devkit etc. I tried following the instructions but now everything is just broke. I'm familiar working with Ruby on Rails but never had to install it (was already set up on my work computer) and I find it hard to believe that updating it is this difficult when the whole philosophy behind ruby on rails is simplicity. I've got to be missing something or not using the proper resource.
The current version of ruby on my machine is ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
$rails --version
Rails 3.0.3
And the DevKit I downloaded is
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe
from http://rubyinstaller.org/downloads
I then tried to walk through the installation steps on this site https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
It always comes back to a 'make' error or 'json' error.
Maybe I have different versions conflicting??
Now I get the following error when I just try to start WEBrick to run my app:
$ rails s
c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/rubygems_integrat
ion.rb:183:in `stub_source_index170': uninitialized constant Gem::SourceIndex (N
ameError)
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/ruby
gems_integration.rb:303:in `stub_rubygems'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/ruby
gems_integration.rb:246:in `replace_entrypoints'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler/runt
ime.rb:14:in `setup'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.22/lib/bundler.rb:1
10:in `setup'
from c:/rails/thumb/costrecovery/config/boot.rb:8:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from script/rails:5:in `<main>'
Any advice is greatly appreciated.

Installing Webistrano on Debian squeeze 64bits

I'm currently trying to install Webistrano on a freshly installed debian squeeze 64bits, but I'm facing some issues that I can't manage to solve.
Note: The machine is created under Xen environment, I don't think this affect the procedure however it seemed important to mention it.
Procedure:
Informations:
Ruby version: ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Rails version: `Rails 2.3.11
Path modifier with: /usr/lib/ruby/1.8:/var/lib/gems/1.8/bin
Rails env: development
Databases have been created
Databases setups for webistrano are, I believe correct (user/pass/path_to_sock_file)
So, here is what I did:
I first installed the 'basics' packages for such installation:
# apt-get install build-essential ruby rubygems libmysql-ruby libmysqlclient-dev libdbd-mysql-ruby mysql-server unzip rake
Then I have been downloading and extracting the project into /usr/src. After copying and configuring the files for email/databses setups (as suggested by https://github.com/peritor/webistrano), I continued by installing all the gems needed for the project:
bundle install
at this point, the command is stuck and isn't doing anything for an hour.
I know it can happen if the Gemfile is complicate, but it doesn't seem to be the case for me. (see the Gemfile following)
# cat Gemfile
source "http://rubygems.org"
gem 'bundler', "~>1.0.10"
gem "rails", "2.3.11"
gem "mysql"
gem "erubis"
gem "rake"
gem "syntax", "1.0.0"
gem "capistrano", "2.6.0"
gem "open4", "0.9.3"
gem "exception_notification", "2.3.3.0"
group :test do
gem "mocha", "0.9.8"
end
So deciding to go ahead I installed the gems by hands, which once finished gives:
# gem list *gems of Gemfile*
bundler (1.0.10)
rails (2.3.11)
mysql (2.8.1)
erubis (2.7.0)
rake (0.9.2.2)
syntax (1.0.0)
capistrano (2.6.0)
open4 (0.9.3)
exception_notification (2.3.3.0)
mocha (0.9.8)
So I believe everything should be working without having to run: bundle install
This is why I finally tried to create the database's structure with rake:
# rake db:migrate --trace
(in /usr/src/peritor-webistrano-a98ba6b)
rake aborted!
Bundler couldn't find some gems.Did you run `bundle install`?
/usr/src/peritor-webistrano-a98ba6b/config/../config/preinitializer.rb:18
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:28:in `load'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:28:in `preinitialize'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:10:in `boot!'
/usr/src/peritor-webistrano-a98ba6b/config/boot.rb:123
/usr/src/peritor-webistrano-a98ba6b/Rakefile:4:in `require'
/usr/src/peritor-webistrano-a98ba6b/Rakefile:4
/usr/lib/ruby/1.8/rake.rb:2383:in `load'
/usr/lib/ruby/1.8/rake.rb:2383:in `raw_load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2017:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2016:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2000:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28
According to rake error message, apparently some gems aren't properly installed, which seems weird to be, but I guess he can't find it.
So I double check with bundle tool:
# bundle check
Your Gemfile's dependencies could not be satisfied
Install missing gems with `bundle install`
# bundle show
Could not find gem 'mocha (= 0.9.8, runtime)' in any of the gem sources listed in your Gemfile.
And I'm stuck here, I just don't know how to continue.
I google around about mocha or gemfile issue, but haven't found much relevant.
I hope everything is clear and easy to understand as this is my first post.
Thanks for any reply/hints, also if I manage to evolve I'll try keeping you up to date!
Check these instructions:
http://www.gogolek.co.uk/blog/2012/10/web-application-deployment-webistrano-capistrano/
Additionally I had problems with mysql gem installation on my clean debian 6 64-bit, so I had to run
$ apt-get install libmysqlclient-dev ruby-dev
I ended up with following gems installed
Using rake (0.8.7)
Using activesupport (2.3.11)
Using rack (1.1.6)
Using actionpack (2.3.11)
Using actionmailer (2.3.11)
Using activerecord (2.3.11)
Using activeresource (2.3.11)
Using bundler (1.0.10)
Using highline (1.6.20)
Using net-ssh (2.7.0)
Using net-scp (1.1.2)
Using net-sftp (2.1.2)
Using net-ssh-gateway (1.2.0)
Using capistrano (2.6.0)
Using erubis (2.7.0)
Using exception_notification (2.3.3.0)
Using mocha (0.9.8)
Installing mysql (2.9.1) with native extensions
Installing open4 (0.9.3)
Installing rails (2.3.11)
Installing syntax (1.0.0)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.

Ruby on Rails - New to Ruby help with rake db:migrate

I am a new user to Ruby on Rails and am having an issue with: rake db:migrate.
After I bundle install, the following comes up:
$ bundle install
Using rake (0.9.2)
Using abstract (1.0.0)
Using activesupport (3.0.9)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.9)
Using erubis (2.6.6)
Using rack (1.2.3)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.29)
Using actionpack (3.0.9)
Using mime-types (1.16)
Using polyglot (0.3.2)
Using treetop (1.4.10)
Using mail (2.2.19)
Using actionmailer (3.0.9)
Using arel (2.0.10)
Using activerecord (3.0.9)
Using activeresource (3.0.9)
Using bundler (1.0.18)
Using rdoc (3.9.4)
Using thor (0.14.6)
Using railties (3.0.9)
Using rails (3.0.9)
Using sqlite3-ruby (1.2.5)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Then, when I try and rake db:migrate, i get the following:
$ rake db:migrate
Could not find polyglot-0.3.2 in any of the sources
Run `bundle install` to install missing gems.
Anyone have any advice? Thanks.
I am on ruby 1.8.7 and rails 3.0.9
Check where it's installed:
gem list -d polyglot
Run bundle exec to make sure rake uses what's specified in your gemfile:
bundle exec rake db:migrate
Ya..apparently the polyglot gem is not included in your gem file.
Also try doing gem install polyglot...
Hope it helps !
bundle exec rake db:migrate might help too..

Rake 0.8.7 and ActiveSupport 3.0.1

I am running Ruby 1.9.2. I have rake 0.8.7 installed. However running rake inside a Rails application gives me the following:
(in /usr/home/users/dimitar/Rails/spek)
Could not find activesupport-3.0.1 in any of the sources
Try running `bundle install`.
So I go ahead and run bundle install again and everything looks good:
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.1)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.1)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.1)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.1)
Using arel (1.0.1)
Using activerecord (3.0.1)
Using activeresource (3.0.1)
Using bundler (1.0.3)
Using thor (0.14.3)
Using railties (3.0.1)
Using rails (3.0.1)
Using sqlite3-ruby (1.3.1)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.
But rake still gives me the same error message. Any suggestions?
Actually the problem seems to come from the config/boot.rb file:
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gemfile)
Do you have multiple Ruby interpreters installed (maybe via rvm or some other method)? If so, are you sure that the right one is active?
Things to look at:
which ruby
which rake
ruby -e 'puts $:' # To show the LOAD_PATH for gems
I had a similar problem using ruby-1.9.2 and fixed it by upgrading rubygems
sudo gem update --system
I had the same problem when I was using REE 1.8.7. I switched to 1.9.2 and did bundle install. Then my rake commands worked.
I had this issue when I mistakenly ran passenger with ruby 1.9.3 and the app used 1.8.7 in its .rvmrc. Fixed by using 1.9.3 (now I have encoding problems, but thats a different story).

Resources