bundle install fails with 'ERROR: Gem bundler not installed' - ruby-on-rails

I have bundler-1.1.3 installed. I have an app that I am trying to get to run. but when I do
$cd my_app
$bundle install
the command fails with this error:
ERROR: Gem bundler not installed
I can run bundle install from anywhere else on the sytem, but not within the app folder.
What could be the problem ?

The .rvmrc file in the directory of the app is saying it needs 1.9.2 to run. RVM has a concept of gem sets that are associated with different versions of ruby on your comptuer. You probably don't have the bundler gem installed under your 1.9.2 version of ruby but another version, perhaps 1.8.7 or 1.9.3.
$ cd my_app
$ rvm use 1.9.2
$ gem install bundle
$ bundle install

Related

Bundler version wrong?

I'm having trouble creating a new Rails app. I'm using a fresh WSL2 + Ubuntu 18.04 install.
Long story short, I followed the Rails installation procedure from https://gorails.com/setup/windows/10 but when installing bundle using gem install bundler, I end up with 2 bundler versions (2.1.2 and 2.1.4).
If I stick with 2.1.2 webpacker throws an error, so I definitely need to install the newest version. The problem is, when I install 2.1.4 the default version remains 2.1.2, so then I go to cd /.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/specifications/default and remove bundler-2.1.2.gemspec, and then I do a gem install bundler --default to get only v2.1.4 as default:
gem list bundler
*** LOCAL GEMS ***
bundler (default: 2.1.4)
But here is the problem; if I run bundler -v I get:
bundler -v
Bundler version 2.1.2
But the real problem is that, when running rails new, it clearly tries to use 2.1.2 which inevitably fails.
How can I solve this?
Thank you
Try gem uninstall bundler --version 2.1.2.
From the app directory run these commands:
gem install bundler
bundle update --bundler
bundle install
This rebuilds the Gemfile.lock with the correct Bundler version.
EDIT: You can create the directory first with rails new my_rails_app, then do cd .. ; rails new my_rails_app after running the above commands.

Installing Ruby - Digital Ocean - RVM - Unstable ruby version - Can't install Gems

I am trying to install Ruby & Rails on DigitalOcean droplet, I have downloaded ruby 2.5.1 with RVM but when I check version it says 2.31 and when I list available versions I get only 2.5.1.
I have tried rvm use 2.5.1 I got below problem
I fix it by running source ~/.rvm/scripts/rvm , then rvm use 2.5.1 and run bundle install, I get the following error,
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
Below show the unstable issues faced from RVM and ruby versions
UPDATE
When I ssh into the server and run ruby -v, I get 2.5.1, then if I run
/bin/bash --login
I check ruby -v, its 2.5.1
install ruby 2.5.1 first, from your image it seems rvm already installed correctly
you just need to install it (it shows from your list command)
rvm install 2.5.1
# this to install version 2.5.1
rvm use 2.5.1
# active ruby 2.5.1
ruby -v
# check your version and make sure it said 2.5.1
to install bundler to your home directory use
# after you active ruby 2.5.1 then install bundler
gem install bundler
# my suggestion do not install with sudo
# in case you still has write problem below is other solution suggested [from here][1]
gem install bundler --user-install
This will install Bundler into your home directory. Note that you will need to append ~/.gem/ruby//bin to your $PATH variable to use bundle.

Gems not in Local Gems after bundle install

New machine. New rbenv install. New rbenv-gemset install. New ruby-2.0.0 install. New rails 4.0.0 app.
When I
$ bundle install
from the rails app directory, I get
Your bundle is complete!
It was installed into ./vendor/bundle
But, if I then
$ gem list
none of the gems that were supposedly installed show up.
I have run
$ rbenv rehash
Why could this be?
Additional info:
$ which bundle
/usr/local/var/rbenv/shims/bundle
$ rbenv which bundle
/usr/local/var/rbenv/versions/2.0.0-p247/bin/bundle
$ rbenv which ruby
/usr/local/var/rbenv/versions/2.0.0-p247/bin/ruby
$ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
$ rbenv gemset active
blog
$ which rails
/usr/local/var/rbenv/shims/rails
Your default in this app is to install to vendor/bundle. You can tell this by It was installed into ./vendor/bundle text which appears after gems installation.
Bundler documentation specifies that you have to pass --system to install in system location:
--system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even
if the bundle was previously installed somewhere else for this
application
EDIT: More explanation is that your ruby knows only about gems installed with --system option when not using bundle exec. You can see your gems from vendor/bundle or whatever path you've chosen by running bundle exec gem list or (as Casper noticed) bundle list. Now it is your choice whether you want your gems in system location or in application directory.

RVM bundler installed ERROR: Gem bundler is not installed, run `gem install bundler` first

I get to work with a new project and it's based on ruby 1.8.7, I'm using rvm to manage my ruby versions and I have installed 1.8.7 and 1.9.2.
The thing is when I do:
rvm use 1.8.7
and try to run:
bundle install
I get:
ERROR: Gem bundler is not installed, run `gem install bundler` first.
I've installed bundler 5 times and even after that it says it's not installed. What can cause this? Bundle even shows up at my gem list.
update from comments:
The ouput of the which ruby && which gem is:
/home/username/.rvm/rubies/ruby-1.8.7-p371/bin/ruby
/home/username/.rvm/bin/gem
Output of "env | grep -iE 'ruby|rvm|gem' | sort":
GEM_HOME=/home/username/.rvm/gems/ruby-1.8.7-p371#global
GEM_PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global
IRBRC=/home/username/.rvm/rubies/ruby-1.8.7-p371/.irbrc
MY_RUBY_HOME=/home/username/.rvm/rubies/ruby-1.8.7-p371
PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global/bin:/home/username/.rvm/rubies/ruby-1.8.7-p371/bin:/home/username/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
RUBY_VERSION=ruby-1.8.7-p371
rvm_bin_path=/home/username/.rvm/bin
rvm_delete_flag=0
rvm_path=/home/username/.rvm
rvm_prefix=/home/username
rvm_ruby_string=ruby-1.8.7-p371
rvm_sticky_flag=1
rvm_use_flag=1
rvm_version=1.17.7 (stable)
Unistalled and installed 1.8.7 via RVM
ran:
rvm install 1.8.7 --verify-downloads 1
and it worked.
It looks like you're probably running the wrong version of gem. In my RVM setup, using the shell command overrides recommended with RVM (source "$HOME/.rvm/scripts/rvm" in your .bashrc or .zshrc or another suitable startup file), gem is normally a shell function. It does some RVM magic under the covers and then runs the real gem command. In my case, both ruby and gem run out of the same version directory:
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/gem
Make sure you're sourcing the RVM startup script.
Your PATH looks ok. Make sure you have a /home/username/.rvm/rubies/ruby-1.8.7-p371/bin/gem command. If not, you may have to reinstall ruby-1.8.7.
Running rvm current will show which Ruby version and gemset are being used. Make sure there's a gem in the path that matches the Ruby version.
rvm install ruby-1.9.2-p320
use this and remember close all terminal
and in edit-> profile preferences--> title and command -->> check (Run command as login shell)

problem with bundle

I try command bundle install --local
but it show issue:
-bash: /usr/local/bin/bundle: /usr/local/bin/ruby: bad interpreter: No such file or directory.
please help me.
The solution that worked for me was entirely different, perhaps because I've been inconsistent about using RVM or not.
I used 'which bundler' to find out where bundler was being launched, it was from /usr/bin/bundler. Noticing that /usr/bin/bundler began with a location and version of ruby that did not exist on my system any more, I did
gem uninstall bundler
gem install bundler
Checking 'which bundler' again confirmed that bundler was now installed within a .rvm environment instead of /usr/bin/bundler, and now references the correct version of ruby; so bundle install now works for my rails project.
I think you need to export the path of ruby and bundle in your .bashrc (linux).
Open your .bashrc and add this line:
export PATH="$PATH:/usr/bin:/usr/local/bin/"
It should work.
The bundle executable is provided by the bundler gem. If you are using rvm then seeing which bundle in /usr/local/bin/bundle indicates a problem, because use of rvm means gems like bundler are installed under your home directory, usually in ~/.rvm/gems/....
# Symptoms of a broken bundler installation:-
# Cannot start Rails...
$ bin/rails s
/Users/rogermarlow/project/config/boot.rb:9:in 'rescue in <top (required)>': uninitialized constant Bundler (NameError)
# bundle not working...
$ bundle install
zsh: /usr/local/bin/bundle: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin: no such file or directory
# ^----- that path does not look right, rvm does not put gems there
$ which bundle
/usr/local/bin/bundle
# ^--- I want bundle from something under ~/.rvm/gems
# First check rvm is in effect:
$ rvm reload
RVM reloaded!
$ which ruby
/Users/rogermarlow/.rvm/rubies/ruby-2.3.4/bin/ruby
# ^--looks good, it is an rvm path, not /usr/local/bin/...
# Now fix bundler
$ gem uninstall bundler # just in case
$ gem install bundler
Fetching: bundler-1.16.1.gem (100%)
Successfully installed bundler-1.16.1
1 gem installed
$ which bundle
/Users/rogermarlow/.rvm/gems/ruby-2.3.4#project/bin/bundle
$ ^--- that is better, bundle is on a path controlled by rvm
# bundle now working
$ bundle install
Fetching gem metadata from http://rubygems.org/..........
*snip*
# rails now working
$ bin/rails s
=> Booting Thin
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
*snip*
On my side, I am using rbenv.
When I checked the /usr/local/bin/bundle, it shows it is using the older ruby, thus causing the problem.
#!/usr/bin/ruby1.9.1
by changing it to point to proper ruby fix the problem
#!/home/user/.rbenv/shims/ruby
For newly created gem-set gem bundler is missing for me,
Before bundler install path for it, /usr/local/bin/bundler
Installed bundler to resolve issue.
gem install bundler --no-ri --no-rdoc
Bundler path changes to, /home/root/.rvm/gems/ruby-2.2.1#drag-drop-list/bin/bundler
Encountering this same problem,
I found bundler installation in /var/lib/gems/2.3.0/gems/bundler-1.16.1;
Then i fixed the error by creating a symbolic link like this:
ln -s /var/lib/gems/2.3.0/gems/bundler-1.16.1/
/usr/lib/ruby/gems/2.3.0/gems/bundler-1.16.1
I did this because I needed this version of ruby.

Resources