Using $ sudo bundle exec ... raises 'bundle: command not found' error
Dan Carley's rbenv-sudo looks like it will do what you want:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
A more detailed explanation of how it works is provided in this article: Sudo Rbenv Me a Sandwich
Why is sudo: bundle command not found?
Check if the PATH
has the same values both with and without sudo
. Apparently it cannot find bundle
just because it is not listed in PATH
You can compare the outputs of following two lines
$ echo 'echo $PATH' | sh
$ echo 'echo $PATH' | sudo sh
Ideally sudo
is supposed to leave PATH
untouched. But this might be a side issue of your hosting distribution.
Edit by original poster. Output is:
[root@desktop etc]# echo 'echo $PATH' | sh
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@desktop etc]# echo 'echo $PATH' | sudo sh
/sbin:/bin:/usr/sbin:/usr/bin:/user/local/bin
[root@desktop etc]#
sudo bundle causes `could not find bundler` error
In order to use bundle
command, you need to install bundler
first:
sudo gem install bundler
Then you will be able to use bundle
command:
sudo bundle exec . . .
Checkout bundler official page for more information.
How to fix sudo bundle install
From Bundler's documentation:
By default, Bundler installs gems to the same location as gem install.
In some cases, that location may not be writable by your Unix user. In that case, >Bundler will stage everything in a temporary directory, then ask you for your >sudo password in order to copy the gems into their system location.
From your perspective, this is identical to installing the gems directly into the >system.
You should never use sudo bundle install. This is because several other steps in >bundle install must be performed as the current user:
Updating your Gemfile.lock
Updating your vendor/cache, if necessary
Checking out private git repositories using your user's SSH keys
Of these three, the first two could theoretically be performed by chowning the >resulting files to $SUDO_USER. The third, however, can only be performed by >invoking the git command as the current user. Therefore, git gems are downloaded >and installed into ~/.bundle rather than $GEM_HOME or $BUNDLE_PATH.
As a result, you should run bundle install as the current user, and Bundler will >ask for your password if it is needed to put the gems into their final location.
As a possible solution you can fully uninstall Ruby and its dependencies, and then install Ruby using asdf, RVM or rbenv and run Bundler again.
I use Bundler just to install gems from a gemfile. cd
into the project with the gemfile and run bundle install
. It must find the gemfile and install the gems automatically. I think it's bad to use Bundler inside the home directory.
I have all gems installed here:
~/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems
Bundler: Command not found
You need to add the ruby gem executable directory to your path
export PATH=$PATH:/opt/ruby-enterprise-1.8.7-2010.02/bin
bundle install - command not found - running as root
I added /usr/local/bin
and /usr/local/sbin
to secure_path in /etc/sudoers
sudo visudo
Then change this line:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Changed this to
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
Explanation:
Gems were installed at /usr/local path and without adding this in secure_path, root user cannot run scripts from there. You can check your gems path by running gem env
in shell.
I also had another issue. I installed gems as ec2-user using bundle and default rubygems path in Amazon Linux installed them only for ec2-user, something I did not like so I installed ruby and rubygems from source which has path to installed them at central location under /usr/local. I know it is not recommended by many but I like it this way. By the way, I tried to find a way to change rubygems path but I could not.
Unicorn service upstart script throws -su: bundle: command not found
I found out the issue. Explanation follows,
root user on startup will first su - into the rails user (in this case 'joe') then executes bundle to start up unicorn. rbenv is single user, only 'joe' has bundle installed. The path to bundle is likely stored in my .bashrc file. However .bashrc file which is not invoked by login in through su - and that caused the bundle not installed error.
I included the paths related to rbenv in .profile. This way when root su - into 'joe' the paths are loaded.
Ruby bundle command not found
It's just a ruby script, ruby newvm.rb
should be enough.
If you want to run it under bundle context, then do:
bundle exec ruby newvm.rb
Related Topics
Rails Unable to Convert Unpermitted Parameters to Hash
How to Add to a Serialized Array
Combine Array of Array into All Possible Combinations, Forward Only, in Ruby
How to Skip Has_Secure_Password Validations
Sinatra Configuring Environments on the Fly
Reading and Updating Yaml File by Ruby Code
Is Ruby Really an Interpreted Language If All of Its Implementations Are Compiled into Bytecode
How to Copy File Across Buckets Using Aws-S3 or Aws-Sdk Gem in Ruby on Rails
Rails 3.1 Absolute Url to an Image
How to Compile Ruby to Byte Code as with Python
Storing Arrays in Database Using Activerecord
How Does Ruby's Sort_By {Rand} Work
How to Get a Backtrace from a Systemstackerror: Stack Level Too Deep