I am setting up a new system. I'm using rbenv instead of rvm because rvm changes the definition of 'cd' and that's just evil.
I've got the required version of ruby and rails (I think) installed, but bundler is causing problems:
turlingdrome$ gem install bundler
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/CHANGELOG.md
turlingdrome$ sudo gem install bundler
/usr/local/Cellar/rbenv/1.1.2/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Done installing documentation for bundler after 3 seconds
1 gem installed
turlingdrome$ sudo gem uninstall bundler
Gem 'bundler' is not installed
turlingdrome$ bundler install
Traceback (most recent call last):
2: from /Users/brianp/.rbenv/versions/2.5.3/bin/bundler:23:in `<main>'
1: from /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)
So, I tried using sudo once, and now I think that the permissions are super user... so I'm using sudo. no big deal.
Installing appears to work.
When I try to uninstall, it says it's not installed.
When I try to run it, it finds an executable, but then says it can't find an executable.
I'm using ruby 2.5.3 and rails (I think) 5.2.3.
Rails crashes with:
turlingdrome$ rails -v
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777
Traceback (most recent call last):
4: from bin/rails:3:in `<main>'
3: from bin/rails:3:in `require_relative'
2: from /Users/brianp/work/online-reporting/config/boot.rb:6:in `<top (required)>'
1: from /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler/setup (LoadError)
which I assume is the same issue.
In case this matters, I'm on a mac.
rbenv works by inserting a directory of shims at the front of your PATH:
~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin
Through a process called rehashing, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby—irb, gem, rake, rails, ruby, and so on.
Shims are lightweight executables that simply pass your command along to rbenv. So with rbenv installed, when you run, say, rake, your operating system will do the following:
Search your PATH for an executable file named rake
Find the rbenv shim named rake at the beginning of your PATH
Run the shim named rake, which in turn passes the command along to rbenv
You messed up your rbenv installation.
1) Remove ruby installation outside rbenv
2) rvm implode
3) Clean up your $PATH env variable from ~/.bash_profile or ~/.bashrc
Remove any $PATH reference pointing to ruby, irb, gem or any folder including those bin executable. Consider commenting any $PATH statement from your bash_profile
# export PATH="$HOME/etc/bin:$PATH"
# leave the statement below
# export PATH="$HOME/.rbenv/bin:$PATH
The $PATH variable includes a list of folders:
echo $PATH
home/fabrizio/.rbenv/shims:/opt/android-studio/bin:~/.scripts/bin
if you run gem in your terminal
any .bin executable file included in home/fabrizio/.rbenv/shims or /opt/android-studio/bin is executable from any location in the terminal. When you run gem, the ruby gem command is executed instead of being intercepted from rbenv, because you installed ruby outside of rbenv.
UPDATE BASED ON YOUR FEEDBACK
You must have followed this step when installing ruby 2.5.0 without rbenv so remove from your ~/.bash_profile or ~/.bashrc the following line
PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin"
or any other line which is adding /Users/brianp/.gem/ruby/2.5.0/bin to your $PATH, then uninstall ruby with apt.
Read the following information, additionally always check the location where gems are being installed with gem env:
$ gem env home
# => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...
if the location from anywhere in the terminal is not under ~/.rbenv/ then you are installing the gems in the wrong locations.
LAST RESORT
Delete the gem folder with rm -rf ~/.gem, a similar approach to this post if you can not remove /Users/brianp/.gem/ruby/2.5.0/bin from your $PATH
SOLUTION FOR YOUR LAST ERROR
This error is caused from installing bundler 2.0
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
you need to remove bundler 2.0 and install 1.9.0
Usage of rbenv is a good choice to manage ruby installation on Mac, but it seems that you finished up in a complete mess of broken rbenv/gem/rails/bundler installation and permissions. It it is not worth of fixing it, so I suggest to just get rid of rbenv, remove ~/.rbenv directory and install rbenv with brew again using this guide.
Other ways to check:
Run rbenv-doctor
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Remove ~/.rbenv directory, run rbenv init again and install required version of Ruby
Check that which ruby and which gem points to appropriate location inside ~/.rbenv directory
Things to note:
rbenv and brew, as well as gem do not require sudo, so you should never use it with them
Do not forget to add eval "$(rbenv init -)" in your shell init script, e.g. echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
warning: Insecure world writable dir /Users/brianp/work in PATH, mode 040777
Looks like problem with access rights. Try this:
sudo chmod 755 /Users/brianp/work
Seems to be a permission issue on a folder.
permission denied # rb_sysopen -
/Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/CHANGELOG.md
I'd try to change permissions on the mentioned file / folder using chmod 755 /Users/brianp/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/
There are several posts which handle a similar topic, e.g. this.
Try to delete Gemfile.lockand try to install and use bundler again - I have just found that on Github:
Bundler 2 introduced a new feature that will automatically switch between Bundler v1 and v2 based on the lockfile [...] If you do, it can be fixed by installing the version of Bundler that is declared in the lockfile. This bug was fixed in RubyGems 3.0.0 but backports are now being prepared for previous major versions of RubyGems. We’ll let you know when they become available.
Can you try that?
gem install bundler --user-install
Related
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.
I've been running in circles trying to install the 'twilio-ruby' gem in my rails app to no avail. Every time I try to bundle install I receive errors around libxml. Below is a part of the error I'm receiving when I add 'twilio-ruby' to the gem-file and try to bundle install:
Errno::EACCES: Permission denied # rb_sysopen - /Users/George/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/libxml-ruby-3.0.0/HISTORY
An error occurred while installing libxml-ruby (3.0.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '3.0.0'` succeeds before bundling.
Trying to gem install libxml-ruby results in the error below:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/George/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/libxml-ruby-3.0.0/HISTORY
Any help that points me in the right direction would be much appreciated.
to install correctly rbenv follow the instructions on github for your operating system (Mac or Linux)
rbenv installation
While to better understand this problem, it is connected to security issues. Mac and Linux are Unix based system, where the user logs in and can execute commands on his home directory ~/<user>. If you try to execute a command to run a script in another directory like the root directory / or /bin, you will get an authorization error and you will need to run the command with sudo that stands for system user do.
For this reason, with linux you configure the ~/.bash_profile file
Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.
Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.
so that those command irb, gem, rake, rails when executed from the user they:
Search your PATH for an executable file named rake
Find the rbenv shim named rake at the beginning of your PATH
Run the shim named rake, which in turn passes the command along to rbenv
explanation of shims in rbenv
You can also solve easily this problem by running the command with sudo, but it is not reccommended, as you can read also from the below post where they have the same problem but with rvm,
Why do I get a "permission denied" error while installing a gem?
I am new to programming and am trying to get rails installed on my terminal. I have been following instructions from a friend, installing the xcode command line tools, homebrew, git, rbenv, ruby-build, ruby gems, ruby, and postgres. But whenever, I try $gem install rails, I get the following:
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
This is especially frustrating because when I run $gem list, it says I have rails 3.2.18. Which is peculiar, because when I run $rails v$, it tells me I have Rails 4.2.0.
When I try to use rails rails my new_app
Errno::EACCES: Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
An error occurred while installing rails (4.2.0), and Bundler cannot continue.
Make sure that `gem install rails -v '4.2.0'` succeeds before bundling.
run bundle exec spring binstub --all
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/shared_helpers.rb:83: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
bundler: command not found: spring
Install missing gem executables with `bundle install`
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ bundle install
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/vendor/thor/shell/basic.rb:355: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
Could not locate Gemfile or .bundle/ directory
This is really frustrating, especially for someone new to programming such as myself, so I am seeking help from anybody who might know what is wrong.
Your rbenv installation was incorrectly installed as it had elevated privileges which caused your user account to not have write access to ~/.rbenv.
Issue the following command in order to take of ownership of the directory:
sudo chown -R Russell_Silver ~/.rbenv
Note that some users may have a different rbenv directory, e.g. /usr/local/var/rbenv. This would take the place of ~/.rbenv in the above command.
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"
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.