138

I'm new to Rails and am currently working through a guide. The guide states:

Use a text editor to update the Gemfile needed by Bundler with the contents of Listing 2.1.

source 'https://rubygems.org'

gem 'rails', '3.2.3'

group :development do
  gem 'sqlite3', '1.3.5'
end


# Gems used only for assets and not required
# in production environments by default.

group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :production do
  gem 'pg', '0.12.2'
end

We then install and include the gems using the bundle install command:

    $ bundle install --without production 

If Bundler complains about no such file to load -- readline (LoadError) try adding gem ’rb-readline’ to your Gemfile.)

I followed the steps even adding on gem 'rb-readline' to the Gemfile, but apparently the file can't be found and when I go to my text editor I do see the Gemfile itself. I noticed that they made me put gem 'rails', 3.2.3 and my version of Rails is 3.2.1 so I tried changing it to 3.2.1 but that didn't work either.

Any thoughts or advice would be much appreciated.

oxfist
  • 749
  • 6
  • 22
levelone
  • 2,289
  • 3
  • 16
  • 17

10 Answers10

288

You just need to change directories to your app, THEN run bundle install :)

shivam
  • 16,048
  • 3
  • 56
  • 71
svoisen
  • 3,292
  • 1
  • 18
  • 8
  • 3
    @svoisen, :D Google includes your answer in the snippet when searching this particular problem, btw. Cheers and thanks from the sleep-deprived future! – Jaime Sep 17 '14 at 18:23
  • 1
    BTW you can find your app directory by using the `whereis ` command, ussualy the Gemfile is under /usr/shared/* – 4gus71n Jun 06 '15 at 14:55
  • App could also be in a folder in /opt/ – Mo Beigi Nov 07 '15 at 11:06
  • Just add some clearance that move to the project folder, not 'bin' folder of the project :) –  Sep 07 '16 at 08:54
24

You may also indicate the path to the gemfile in the same command e.g.

BUNDLE_GEMFILE="MyProject/Gemfile.ios" bundle install
shivam
  • 16,048
  • 3
  • 56
  • 71
houbena
  • 339
  • 3
  • 7
  • 2
    Perfect answer. Because in my situation I can't get access bundle command in everywhere. `[root@alc bin]# BUNDLE_GEMFILE="../../apps/redmine/htdocs/Gemfile" ./bundle install` is my command to execute. – uzay95 Jan 30 '15 at 10:43
  • 1
    For some reason I was having this issue when I was copying a Gemfile into a docker container, I couldnt find a .bundle and I had set my WOKRDIR but it didnt seem to catch it for bundle install, this did the trick! – ConstantineK Mar 22 '16 at 03:15
22

I had this problem as well on an OSX machine. I discovered that rails was not installed... which surprised me as I thought OSX always came with Rails. To install rails

  • sudo gem install rails
  • to install jekyll I also needed sudo
  • sudo gem install jekyll bundler
  • cd ~/Sites
  • jekyll new <foldername>
  • cd <foldername> OR cd !$ (that is magic ;)
  • bundle install
  • bundle exec jekyll serve
  • Then in your browser just go to http://127.0.0.1:4000/ and it really should be running
MAILO
  • 237
  • 2
  • 5
  • 2
    Avoid using `sudo` to install gems. This will cause you pain. Read more: https://thoughtbot.com/blog/psa-do-not-use-system-ruby – David Hempy Mar 05 '20 at 13:39
15

You must be in the same directory of Gemfile

forzagreen
  • 2,509
  • 30
  • 38
10

I had this problem on Ubuntu 18.04. I updated the gem

sudo gem install rails
sudo gem install jekyll
sudo gem install jekyll bundler
cd ~/desiredFolder
jekyll new <foldername>
cd <foldername> OR 
bundle init
bundle install
bundle add jekyll
bundle exec jekyll serve

All worked and goto your browser just go to http://127.0.0.1:4000/ and it really should be running

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
osmjit
  • 381
  • 3
  • 10
8

When I had similar problem gem update --system helped me. Run this before bundle install

Dzianis Yafimau
  • 2,034
  • 1
  • 27
  • 38
3

In my case this worked:

  • cd /usr/bin
  • touch Gemfile
  • Now you can then run bundle install.
Anton Krug
  • 1,555
  • 2
  • 19
  • 32
2
  1. Make sure that the file name is Capitalized Gemfile instead of gemfile.
  2. Make sure you're in the same directory as the Gemfile.
Adam A Allalou
  • 1,503
  • 1
  • 8
  • 8
-1

Search for the Gemfile file in your project, go to that directory and then run "bundle install". prior to running this command make sure you have installed the gem "sudo gem install bundler"

-15

Think more about what you are installing and navigate Gemfile folder, then try using sudo bundle install

Cookie
  • 1
  • 1