problem with bundle - ruby-on-rails

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.

Related

Rails command not available after installing with gemfile

I installed rails via a Gemfile and bundle install:
Gemfile
source "https://rubygems.org"
gem "rails", "5.0.6"
the gem appears to have successfully installed according to success message. However it is still not available from the command line even after a restart.
$ rails
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
You will have to enable the component called 'universe'
I am using rbenv (required) and have a number of utilities in /.rbenv/shims/ (gem, rake, bundle, etc.) but not rails... so I don't know where it got installed.
gem env returns:
GEM PATHS:
- /home/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
- /home/user/.gem/ruby/2.5.0
but I don't see those packages there. I'm guessing it needs to be on the path, but I don't know where it is. The solution needs to work while installing with a bash script.
just add bundle exec
bundle exec rails
When you use rbenv and you install Ruby on Rails then you might need to run rbenv rehash to make the rails command available.
From the docs:
Installs shims for all Ruby executables known to rbenv (i.e., ~/.rbenv/versions/*/bin/*). Run this command after you install a new version of Ruby, or install a gem that provides commands.
after I read your problem, I guess that you used rbenv and you didn't run rbenv rehash, so you can do it as following below:
gem install railties
rbenv rehash
So, I was running rbenv rehash and setting the environment variable. However, the new env variables were not available until after a restart. Using the full path to /.rbenv/shims/rake solved the problem.

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)

bundle install fails with 'ERROR: Gem bundler not installed'

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

Rails: "Could not find bundler" (2.2.11) required by Gemfile.lock. (Gem::GemNotFoundException)

When I try to do bundler update I get this error:
.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in
`to_specs': Could not find bundler (>= 0) amongst
[rake-0.8.7, rake-0.8.7, rubygems-update-1.8.4] (Gem::LoadError)
I'm new to Ruby, can someone tell me what would cause this? Rake 0.8.7 is installed.
Make sure you're entering "bundle" update, if you have the bundler gem installed.
bundle update
If you don't have bundler installed, do gem install bundler.
I had this problem, then I did:
gem install bundler
then in your project folder do:
bundle install
and then you can run your project using:
bundle exec rails server
I had the same problem. This worked for me:
run rvm/script/rvm and also add it to your .profile or .bash_profile as shown in https://rvm.io/rvm/install/
use bundle without sudo
If You are using rvm, then try the following command:
rvmsudo gem install bundler
According to another question: Could not find rails (>= 0) amongst [] (Gem::LoadError)
Hope it helped,
Cheers
The command is bundle update (there is no "r" in the "bundle").
To check if bundler is installed do : gem list bundler or even which bundle and the command will list either the bundler version or the path to it. If nothing is shown, then install bundler by typing gem install bundler.
I had the same problem .. something happened to my bash profile that wasn't setting up the RVM stuff correctly.
Make sure your bash profile has the following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Then I ran "source ~/.bash_profile" and that reloaded everything that was in my bash profile.
That seemed to fix it for me.
According to this answer to a similar question, it should be enough:
rvmsudo gem install bundler.
Cheers
If you're using rbenv running rbenv rehash can solve this after you've installed bundler and are still getting the issue.
You may have to do something like "rvm use 1.9.2" first so that you are using the correct ruby and gemset. You can check which ruby you are using by doing "which ruby"
I had this same concern when setup a new Bundler gem version (2.2.11) on my machine.
I was getting the error below:
/home/username/.rbenv/versions/2.7.2/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.11) required by your /home/username/Projects/my_project/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.11`
17: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `<main>'
16: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `load'
15: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec:4:in `<top (required)>'
14: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/lib/rspec/core/runner.rb:45:in `invoke'
Here's how I achieved it:
First, I had already installed the Bundler gem 2.2.11 and made it the default gem:
gem install --default bundler -v 2.2.11
Next, I listed my Bundler versions:
gem list bundler
Finally, I updated my gems to use the newly installed Bundler:
gem update --system
That's all.
I hope this helps
I got this after upgrading to ruby 2.1.0. My PATH was set in my login script to include .gem/ruby/2.0.0/bin. Updating the version number fixed it.
The system might be running "rootless". Try to set the firmware nvram variable boot-args to "rootless=0".
Try to run set of commands:
sudo nvram boot-args="rootless=0";
sudo reboot
After reboot completes, run:
sudo gem install bundler
Can be related to https://github.com/bundler/bundler-features/issues/34 if you are running the command inside another bundle exec. Try using Bundler.with_original_env if that is the case.
For anyone encountering this issue with Capistrano: capistrano isn't able to locate the bundler. The reason might be that you installed bundler under some other gemset where the Capistrano isn't even looking.
List your gemsets.
rvm gemset list
Use a particular gemset.
rvm use 'my_get_set'
Install bundler under that gemset.
gem install bundler
Then, try again with the deploy task.
I resolved it by deleting Gemfile.lock and gem install bundler:2.2.0
In my case I believe I had an old Ruby remaining on the system, not registered on rvm, and even if the path variables and gem list was okay, it would still use the old Ruby during deployments with Capistrano
And then I realized, the Ruby I had installed with rvm wasn't set to the default one. Running
rvm alias create default <rvm_registered_ruby>
Fixed it.
Just in case, I had similar error with bundler 2.1.2 and solved it with:
sudo gem install bundler -v 1.17.3
If you have several bundler versions installed, then you can run specific version of bundle this way: bundle _1.17.3_ exec rspec
Though seems like later bundler versions are pretty buggy (had issues on 3 different projects on 2 operation systems), having one old bundler may work the best, at least this is what I have on my Ubuntu & MacOS
Latest bundler versions may override stable bundler -v 1.17.3.
It can be not easy to remove latest bundler from system, here is what helped me:
Remove default version from gem env gempath: https://stackoverflow.com/a/60550744/1751321
Remove rm bundler.rb && rm -rf bundler folder from load paths: ruby -e 'puts $LOAD_PATH'
Then reinstall stable gem install bundler -v 1.17.3 (Not sudo! it is important)
Script ruby fix_bundler.rb
require 'fileutils'
load_paths = `ruby -e 'puts $LOAD_PATH'`
load_paths.split.each do |path|
target = File.join path, "bundler.rb"
if File.exist? target
puts "Deleting #{target}"
File.delete target
end
target = File.join path, "bundler"
if File.directory? target
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
Gem.paths.path.each do |path|
path_mask = File.join path, "specifications", "default", "bundler*"
Dir[path_mask].each do |target|
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
puts "✅ bundler fixed"

Resources